I'm new to VBA and trying to write a macro/code to compare list of dates to range of dates. In my spreadsheet, Col A shows list of due dates, Col D shows start dates, Col E shows end dates, Col F shows the corresponding week number of inclusive Start Date and End Date, i.e. 1, 2, 3, 4 up to 15 weeks. I want to compare the date on Col A to the Col D (Start date) and Col E (End date) if it matches and within the date range between start and end dates, put the week number on Col B. However, if it does not match to the range date, compare it to the next week range (loop?) until it find the match week range and put the corresponding week number on Col B. Any suggestions will be appreciated.
Solution to this post from Nimrod:
Public Sub GetWeek()
c = Cells(65536, 1).End(xlUp).Row
' The specific Date loop
For rw = 1 To Cells(65536, 1).End(xlUp).Row
If IsDate(Cells(rw, 4)) Then
frmProgress.ProgressBar.Value = (rw / c) * 100
' The StartDate-EndDateLoop
For Rww = 1 To Cells(65536, 12).End(xlUp).Row
If IsDate(Cells(Rww, 12).Value) Then
If Cells(rw, 4).Value >= Cells(Rww, 12).Value And _
Cells(rw, 4).Value <= Cells(Rww, 13).Value Then
Cells(rw, 8).Value = Cells(Rww, 11).Value
End If ' between dates
End If ' is start date
Next Rww ' next start date
End If ' is date
Next rw
End Sub
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks