AlexanderBB
Well-known Member
- Joined
- Jul 1, 2009
- Messages
- 2,097
- Office Version
- 2019
- 2010
- Platform
- Windows
Should return the First and Last Row numbers in column "C" for Yr in Sheet sht
It works correctly in some sheets but in one other I get
Run-time error '91':
Object variable or With block variable not set.
The only difference I can see in the sheet not working is it has only columns A-Z showing. And sometimes a message about can't shift object off sheet when Cut/insert row.
VBA Code:
Sub YrRange(Yr, ByRef First, ByRef Last, sht)
Last = ThisWorkbook.Sheets(sht).Range("C:C").Find(What:=Yr & "*", LookAt:=xlWhole, lookIn:=xlValues, SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
First = ThisWorkbook.Sheets(sht).Range("C:C").Find(What:=Yr & "*", LookAt:=xlWhole, lookIn:=xlValues, SearchOrder:=xlByRows, SearchDirection:=xlNext).Row
End Sub
Run-time error '91':
Object variable or With block variable not set.
The only difference I can see in the sheet not working is it has only columns A-Z showing. And sometimes a message about can't shift object off sheet when Cut/insert row.