My worksheet consists of several rows - Row 3 is a list of (increasing) Month End dates from 42400 (31/01/2016) to 44926 (31/12/2022). The dates are listed as numbers, formatted as dd/mm/yyyy. The object of the exercise is to find the column which is headed 31/12/2021 (Check_Year)
Dim Check_Year As Integer 'Line 1
Dim ColNo As Integer 'Line 2
Check_Year = 2121 'Line 3
Windows("My Workbook.xlsm").Activate 'Line 4 - open "My Workbook" workbook
Sheets("My worksheet").Select 'Line 5 - Select the worksheet "My worksheet"
ActiveWindow.Panes(1).Activate 'Line 6 - Activate worksheet
ActiveCell(3, 1).Select 'Line 7 - select Cell Column A, Row 3
Range("3:3").Select 'Line 8 - Select (the whole of) Row 3
Selection.Find(What:="31/12/" & Check_Year, After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate 'Lines 9 to 11 - select the month end date row (Row 3) and find the 31st December for the Check_Year
ColNo = (ActiveCell.Column - 1) 'Line 12 - "ColNo" is the column immediately before the column "31/12/2021"
'I keep getting error "Object variable or With block variable not set" for Lines 9 to 11, I understand that I should be defining an "Object" (with "Set"), but I can't figure out what should be set and where in the programme it fits. Further more, I'm not sure I need lines 6 & 7. I would be most grateful for your help.