0

I am writing the code to delete the records with the oldest date in the table, using the function to find the end of the range. I never get the "endrow" value back to the sub. Appreciate any suggestion.

StartDate = ActiveSheet.Cells(2, 1).Value
EndDate = StartDate
startrow = 2
endrow = FindEndDate(EndDate)
Rows(startrow & ":" & endrow).EntireRow.Delete

Function FindEndDate(ByVal EndDate As Date) As Long
lastrow = Cells(Rows.Count, 1).End(xlUp).Row
    For i = lastrow To 2 Step -1
        If Cells(i, 1).Value = EndDate Then
            endrow = i
            Exit For
        End If
    Next i
End Function
JandB
  • 1
  • 1
  • It would be good to read up on [scope](https://learn.microsoft.com/en-us/office/vba/language/concepts/getting-started/understanding-scope-and-visibility). – BigBen Feb 01 '22 at 18:14
  • Also [writing a function](https://learn.microsoft.com/en-us/office/vba/language/concepts/getting-started/writing-a-function-procedure). – BigBen Feb 01 '22 at 18:20

0 Answers0