인프런 커뮤니티 질문&답변
한셀 2018 VBS 오류
작성
·
12
0
안녕하세요. 업무를 더 효율적이게 하고 싶어서 VBS를 사용해봤는데, 계속 Expected end of statement. 줄 수: 3으로 에러가 나요. 뭐가 잘못됐는지 피드백 부탁드리겠습니다.
Sub 최종()
Dim ws As Object
Set ws = ActiveSheet
Dim LastRow As Long
LastRow = ws.Cells(ws.Rows.Count, "K").End(xlUp).Row
If LastRow < 2 Then
MsgBox "K열에 데이터가 없습니다.", vbExclamation
Exit Sub
End If
Dim Count As Long
Count = 0
Dim i As Long
Dim kDate As Date
Dim diffDays As Long
Dim todayDate As Date
todayDate = DateSerial(2026, 1, 5) ' 2026년 1월 5일 기준 고정
' --------- 365일 이상 ---------
For i = 2 To LastRow
If Trim(ws.Cells(i, "A").Value) <> "" Then
If Trim(ws.Cells(i, "N").Value) = "연기 대상" Then
If IsDate(ws.Cells(i, "K").Value) Then
kDate = CDate(ws.Cells(i, "K").Value)
diffDays = DateDiff("d", kDate, todayDate) + 1 ' 출국일 포함 경과일수
If diffDays >= 365 Then
Count = Count + 1
End If
End If
End If
End If
Next i
If Count = 0 Then
MsgBox "보류 대상자. ", vbInformation
Exit Sub
End If
' --------- <보류> ---------
Dim Result As String
Result = "<보류승인>" & vbCrLf & _
"보류" & vbCrLf & _
"보류 (" & Count & "명)" & vbCrLf & vbCrLf
' --------- 대상자 목록 (번호 자동 부여) ---------
Dim cnt As Long
cnt = 1
For i = 2 To LastRow
If Trim(ws.Cells(i, "A").Value) <> "" Then
If Trim(ws.Cells(i, "N").Value) = "보류 대상" Then
If IsDate(ws.Cells(i, "K").Value) Then
kDate = CDate(ws.Cells(i, "K").Value)
diffDays = DateDiff("d", kDate, todayDate) + 1
If diffDays >= 365 Then
Result = Result & cnt & ". " & _
Trim(ws.Cells(i, "C").Value) & " " & _ ' 계급 (C열 가정)
Trim(ws.Cells(i, "D").Value) & " " & _ ' 성명 (D열 가정)
Format(kDate, "yyyy.mm.dd") & " 출국 ~ " & _
Format(todayDate, "yyyy.mm.dd") & " (" & diffDays & "일 경과)" & vbCrLf
cnt = cnt + 1
End If
End If
End If
End If
Next i
' --------- 결과 Z1 셀에 출력 ---------
ws.Range("Z1").Value = Result
' Z1 셀 서식 정리 (줄바꿈 적용 및 글꼴)
With ws.Range("Z1")
.WrapText = True
.VerticalAlignment = xlTop
.Font.Name = "맑은 고딕"
.Font.Size = 10
End With
MsgBox "보류 완료 (" & Count & "명)" & vbCrLf & _
"결과를 Z1 셀에 저장했습니다." & vbCrLf & _
"기준일: 2026년 1월 5일", vbInformation
End Sub
답변




