I am working with daily data that recorded 31 days of data per multiple stations and I need a VBA code to remove leap year days. I have a list of dates of data recorded and a list of years that are not leap years that I want to delete. To delete the extra 30 and 31 days, I used the basic following code:
Dim lastrow, i As Long
lastrow = ActiveSheet.Cells(65536, 1).End(xlUp).Row
For i = 1 To lastrow
'delete 31st days for February
If ActiveSheet.Range("D" & i) = 2 And ActiveSheet.Range("E" & i) = 31 Then
Rows(i).Select
Selection.Delete shift:=xlUp
End If
Next i
Pretty simple and works nicely so I was hoping to be able to do something similar where I find the non-existent date (ie. 02/29/non-leapyear) within the data and delete the row but it has turned out to be extremely difficult to match a value within a range. I was thinking along the lines of something like this:
Dim lastrow, i As Long, leapyear as Workbook
Set leapyear = Workbooks("LeapYears.xlsx")
lastrow = ActiveSheet.Cells(65536, 1).End(xlUp).Row
For i = 1 To lastrow
'obviously this is where I have the problem trying to match a cell to a range
If ActiveSheet.Range("D" & i) = leapyear.Sheets(1)range("C2:C90") Then
Rows(i).Select
Selection.Delete shift:=xlUp
End If
Next i
Any help or another way to handle this is greatly appreciated!