[VB] 휴일제외하고 날짜 구하기.
첨부파일 있음.
—————————————-
Dim g_returnValue
Sub Macro1()
‘
‘ Macro1 Macro
‘
‘ 바로 가기 키: Ctrl+k
‘
If ActiveCell.Offset(0, 0).Value = “” Then
MsgBox (“현재 셀에 값이 존재하지 않습니다.”)
Exit Sub
End If
If ActiveCell.Offset(0, -1).Value = “” Then
MsgBox (“좌측 셀에 값이 존재하지 않습니다.”)
Exit Sub
End If
If ActiveCell.Offset(0, -1).Value < 0 Then
ActiveCell.Offset(0, 1).Value = ActiveCell.Offset(0, 0).Value
ActiveCell.Offset(1, 0).Select
Exit Sub
End If
Dim dt1 As Date
dt1 = ActiveCell.Offset(0, 0).Value
Dim plusNum
plusNum = ActiveCell.Offset(0, -1).Value
Dim holydayArray(10) As Date
holydayArray(0) = “2018-01-01”
Call addDateWithHoliday(dt1, plusNum, holydayArray)
ActiveCell.Offset(1, 0).Select
End Sub
Function addDateWithHoliday(orgDate, targetNum, holydayArray)
Dim curNum
curNum = 0
Dim newDate As Date
newDate = orgDate
Dim yoil
Dim limitLoop
limitLoop = 300
Dim curLoop
curLoop = 0
Do
curLoop = curLoop + 1
If curLoop > 100 Then
Exit Do
End If
newDate = DateAdd(“d”, 1, newDate)
‘yoil = Right(newDate, 1)
yoil = WeekdayName(Weekday(newDate))
yoil = Left(yoil, 1)
‘MsgBox (yoil)
Call hasValueInArray(newDate, holydayArray)
If yoil = “토” Or yoil = “일” Then
ElseIf g_returnValue = True Then
Else
curNum = curNum + 1
If curNum >= targetNum Then
Exit Do
End If
End If
Loop
ActiveCell.Offset(0, 1).Value = newDate
End Function
Function hasValueInArray(targetValue, targetArray)
Dim count
count = UBound(targetArray)
g_returnValue = False
For i = 0 To count
If targetArray(i) = targetValue Then
‘일치
g_returnValue = True
Else
‘불일치
End If
Next i
End Function