Hi all:
I am struggling with workday function in VBA using Excel 2003. Finally decided to ask masters. Here is my requirement:
Column A has dates (format: 24/12/2014).
Other cell: M2, has value: 11, it may change.
Need VBA code: a) read last row (e.g. R503) in column A and its value (which is date: 24/12/2014).
b) in last date (24/12/2014) add one (e.g. 24/12/2014 + 1) and get next date (EXCLUDING weekend (sat & sun) and EXCLUDE other stat holidays (list of holidays is in same workbook, worksheet: Holidays (column A, no heading).
c) put next date in next row e.g. R504 (column A, e.g. R503 +1)
d) loop through/repeat above process 11 times (or till M2 = 11) and keep filling next row of column A with next date.
I have following code that does all work but I am unable to exclude weekend and other holidays. I know how to use WORKDAY function in excel but unable to handle in VBA.
Any proven solution will be highly appreciated. Know less about VBA.
My working code:
Thanks
Ria
I am struggling with workday function in VBA using Excel 2003. Finally decided to ask masters. Here is my requirement:
Column A has dates (format: 24/12/2014).
Other cell: M2, has value: 11, it may change.
Need VBA code: a) read last row (e.g. R503) in column A and its value (which is date: 24/12/2014).
b) in last date (24/12/2014) add one (e.g. 24/12/2014 + 1) and get next date (EXCLUDING weekend (sat & sun) and EXCLUDE other stat holidays (list of holidays is in same workbook, worksheet: Holidays (column A, no heading).
c) put next date in next row e.g. R504 (column A, e.g. R503 +1)
d) loop through/repeat above process 11 times (or till M2 = 11) and keep filling next row of column A with next date.
I have following code that does all work but I am unable to exclude weekend and other holidays. I know how to use WORKDAY function in excel but unable to handle in VBA.
Any proven solution will be highly appreciated. Know less about VBA.
My working code:
Code:
Sub nextDate ()
Dim FLD_Count As Integer, I As Integer, LR As Long, LRDate As Long, nextRow As Long, nextDate As Long
FLD_Count = ActiveSheet.Range("M2").Value
LR = ActiveSheet.Range("A" & Rows.count).End(xlUp).Row
LRDate = ActiveSheet.Range("A" & LR).Value
' Begin the loop.
For I = 1 To FLD_Count
ActiveSheet.Range("A" & LR + I) = LRDate + I
' ActiveSheet.Range("A" & LR + I) = Workday(LRDate, LRDate + I)
Next I
End Sub
Thanks
Ria