ItalianPlatinum
Well-known Member
- Joined
- Mar 23, 2017
- Messages
- 774
- Office Version
- 365
- 2019
- Platform
- Windows
Hello - I am looking to modify existing code I have been leveraging where I have been defining the range of dates in a separate sheet and I want to move to a more automated approach where it loops through a START and a END within the code. Those dates I already have defined in other codes as set ranges. Any help is appreciated.
Start date = RUNDATE
End date = FFWD
The code currently runs Date 1 with view A, Date 1 with view B then until view is empty then moves to Date 2 and so on.
Existing VBA:
Start date = RUNDATE
End date = FFWD
The code currently runs Date 1 with view A, Date 1 with view B then until view is empty then moves to Date 2 and so on.
Existing VBA:
VBA Code:
Option Explicit
Sub RUN_DATE_LOOP()
Dim Views
Dim colno
Dim rowno
Dim lastrow
Dim alldates
Dim j As Long
Dim i As Long
Dim Dates As Date
With Sheets("Date Loop")
' find the last row with data in that column
lastrow = .Cells(rows.count, "A").End(xlUp).row
' load all the dates into and array
alldates = .Range(.Cells(2, 1), .Cells(lastrow, 1))
Views = Sheets("Views").Range("A2:A5")
End With
For j = 1 To UBound(Views, 1)
Sheets("Sec").Range("View") = Views(j, 1)
For i = 1 To UBound(alldates, 1)
Sheets("Sec").Range("REQDATE") = alldates(i, 1)
Call Sec2
Next i
Next j