Brian Feth
New Member
- Joined
- May 21, 2017
- Messages
- 33
Windows 11, Excel 2021: I am trying to fine the row numbers of the top date in the column (easy) then the first occurance of a chosen date ("11/25/2024") working from the bottom of the column up. I'm trying to use FIND to identify the row number of that date ("11/25/2024"). Can't get it to work. I keep geting the error message "Object Variable or Width Block Variable not set" at the FIND command. You can see I tried a couple of ways to enter the variables into the FIND command. I very much appreciate any help you van give.
VBA Code:
Sub FindDateRange()
Dim TopDate_Row As Integer
'Dim BottomDate_Row As Integer
Dim BottomDate_Row As Variant
Dim TargetDate As Variant
' Find Range of Rows to Delete using FIND . Finds top row (TopRow_Date)then, Finds first occurance of a date ( (bottom up).
TargetDate = Range("Q4").Value '11/25/2024
Range("C5").Select
Selection.End(xlDown).Select
TopDate_Row = Selection.Row 'Row of top Date in Column
Selection.End(xlDown).Offset(1, 0).Select 'goes to "C591", aka bottom of Column range
'BottomDate_Row = ActiveSheet.Columns("C:C").Find(What:=TargetDate, After:=ActiveCell, LookIn:=xlValues, _
SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False, SearchFormat:=False).Row
BottomDate_Row = ActiveSheet.Columns("C:C").Find(What:="11/25/2024", After:=[C591], LookIn:=xlValues, _
SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False, SearchFormat:=False).Row
' Error message "Object Variable or Width Block Variable not set"
End Sub
Last edited by a moderator: