Hi,
I was wondering if you would please help me with a problem that I'm having.
I'm doing some work on a file relating to hotel bookings and want a macro or formula to populate all dates between a start and finish date so I can see exactly which nights they stayed.
I found a macro (below) that does a close approximation but i cant get it to loop down (which is essential as theres a significant number of guests) or populate all dates into one cell for each row rather than put each one into a new column (this would be preferable but not essential).
Any help that you can give me in adapting this or creating a new one would be much appreciated. Please bear in mind that i have limited understanding of vba at the moment.
Many thanks in advance,
Paul
I was wondering if you would please help me with a problem that I'm having.
I'm doing some work on a file relating to hotel bookings and want a macro or formula to populate all dates between a start and finish date so I can see exactly which nights they stayed.
I found a macro (below) that does a close approximation but i cant get it to loop down (which is essential as theres a significant number of guests) or populate all dates into one cell for each row rather than put each one into a new column (this would be preferable but not essential).
Sub WriteDates2()
Dim sc As Range
sd = Range("A2") ' start date
ed = Range("B2") ' end date
Set sc = Range("D2") ' start cell
' check dates
If ed - sd <= 0 Then Exit Sub
j = 0
For i = sd To ed
sc.Offset(0, j) = i
j = j + 1
Next i
End Sub
Dim sc As Range
sd = Range("A2") ' start date
ed = Range("B2") ' end date
Set sc = Range("D2") ' start cell
' check dates
If ed - sd <= 0 Then Exit Sub
j = 0
For i = sd To ed
sc.Offset(0, j) = i
j = j + 1
Next i
End Sub
Any help that you can give me in adapting this or creating a new one would be much appreciated. Please bear in mind that i have limited understanding of vba at the moment.
Many thanks in advance,
Paul