RangeFind Produces Error 424

Turk182

Board Regular
Joined
Sep 9, 2009
Messages
66
Office Version
  1. 365
Platform
  1. MacOS
Hello. Can someone please help. I am not sure why I'm getting this error: "Runtime error 424 Object Required”.

Here is the VBA code:

Sub RangeFind()

Dim lastRow As Long, lastColumn As Long

lastRow = shJagged.Cells.Find(What:="*" _

, LookIAt:=xlPart _

, LookIn:=xlFormulas _

, searchorder:=xlByRows _

, searchdirection:=xlPrevious).Row

lastColumn = shJagged.Cells.Find(What:="*" _

, LookIAt:=xlPart _

, LookIn:=xlFormulas _

, searchorder:=xlByColumns _
, searchdirection:=xlPrevious).Column

rg.Select

End Sub

Thx.
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Hi.
you have a few errors in your code including missing a reference to worksheet object shJagged

VBA Code:
Sub RangeFind()
    Dim shJagged    As Worksheet
    Dim lastRow     As Long, lastColumn As Long
   
    Set shJagged = ThisWorkbook.Worksheets("Jagged")
   
    lastRow = shJagged.Cells.Find(What:="*", LookAt:=xlPart, LookIn:=xlFormulas, _
    searchorder:=xlByRows, searchdirection:=xlPrevious).Row
   
    lastColumn = shJagged.Cells.Find(What:="*", LookAt:=xlPart, LookIn:=xlFormulas, _
    searchorder:=xlByColumns, searchdirection:=xlPrevious).Column
   
    shJagged.Cells(lastRow, lastColumn).Select

End Sub

As you are selecting the range I am assuming sheet Jagged is the activesheet.

Dave
 
Last edited:
Upvote 0
Solution
Hi.
you have a few errors in your code including missing a reference to worksheet object shJagged

VBA Code:
Sub RangeFind()
    Dim shJagged    As Worksheet
    Dim lastRow     As Long, lastColumn As Long
  
    Set shJagged = ThisWorkbook.Worksheets("Jagged")
  
    lastRow = shJagged.Cells.Find(What:="*", LookAt:=xlPart, LookIn:=xlFormulas, _
    searchorder:=xlByRows, searchdirection:=xlPrevious).Row
  
    lastColumn = shJagged.Cells.Find(What:="*", LookAt:=xlPart, LookIn:=xlFormulas, _
    searchorder:=xlByColumns, searchdirection:=xlPrevious).Column
  
    shJagged.Cells(lastRow, lastColumn).Select

End Sub

As you are selecting the range I am assuming sheet Jagged is the activesheet.

Dave
 
Upvote 0
Thanks Dave; adjustments made!
The first error is gone, but this is the new error: “Runtime error 91: object variable with block not set

lastRow = shJagged.Cells.Find(What:="*", LookAt:=xlPart, LookIn:=xlFormulas, _
searchorder:=xlByRows, searchdirection:=xlPrevious).Row


...any idea what in the above code prompts that error?

Thx,
Anthony
 
Upvote 0
Hi,
I suspect that your worksheet contains no data

Try using my updated version of the code & see if helps

VBA Code:
Sub RangeFind()
    Dim shJagged        As Worksheet
    Dim RowCol(1 To 2)  As Variant
    Dim i               As Long
    
    Set shJagged = ThisWorkbook.Worksheets("Jagged")
    
    On Error Resume Next
    For i = xlRows To xlColumns
        With shJagged.Cells.Find(What:="*", After:=shJagged.Range("A1"), LookIn:=xlFormulas, LookAt:=xlPart, _
                            searchorder:=i, searchdirection:=xlPrevious, MatchCase:=False)
            RowCol(i) = Choose(i, .Row, .Column)
        If Err > 0 Then RowCol(i) = 1
        End With
    Next i
     On Error GoTo 0
     
     shJagged.Cells(RowCol(xlRows), RowCol(xlColumns)).Select
End Sub

Dave
 
Upvote 0
Hi,
I suspect that your worksheet contains no data

Try using my updated version of the code & see if helps

VBA Code:
Sub RangeFind()
    Dim shJagged        As Worksheet
    Dim RowCol(1 To 2)  As Variant
    Dim i               As Long
   
    Set shJagged = ThisWorkbook.Worksheets("Jagged")
   
    On Error Resume Next
    For i = xlRows To xlColumns
        With shJagged.Cells.Find(What:="*", After:=shJagged.Range("A1"), LookIn:=xlFormulas, LookAt:=xlPart, _
                            searchorder:=i, searchdirection:=xlPrevious, MatchCase:=False)
            RowCol(i) = Choose(i, .Row, .Column)
        If Err > 0 Then RowCol(i) = 1
        End With
    Next i
     On Error GoTo 0
    
     shJagged.Cells(RowCol(xlRows), RowCol(xlColumns)).Select
End Sub

Dave
Thanks Dave. Both errors are gone now!
 
Upvote 0
welcome glad resolved & appreciate feedback

Dave



HI Dave. Please heip. Both errors definitely are gone (Thx again), but a different type of issue arose:

I THOUGHT the code was going to select

all cells from the last occupied row up,
and from the last occupied column all the way over to the leftmost column.

What it is selecting is the cell at the bottom right (the intersection of
the Last row and last column)….

How can I get the whole range selected?

Thx.
 
Upvote 0
How can I get the whole range selected?

Thx.

If you are using my updated version of the code change this line

VBA Code:
shJagged.Cells(RowCol(xlRows), RowCol(xlColumns)).Select

for this

VBA Code:
shJagged.Cells(1, 1).Resize(RowCol(xlRows), RowCol(xlColumns)).Select

if using your version of code then its this

VBA Code:
shJagged.Cells(1, 1).Resize(lastRow, lastColumn).Select

either version should select from cell A1

Dave
 
Upvote 0
If you are using my updated version of the code change this line

VBA Code:
shJagged.Cells(RowCol(xlRows), RowCol(xlColumns)).Select

for this

VBA Code:
shJagged.Cells(1, 1).Resize(RowCol(xlRows), RowCol(xlColumns)).Select

if using your version of code then its this

VBA Code:
shJagged.Cells(1, 1).Resize(lastRow, lastColumn).Select

either version should select from cell A1

Dave


Hi Dave,
Unfortunately, I get "run-time error 91" again.
 
Upvote 0

Forum statistics

Threads
1,215,219
Messages
6,123,687
Members
449,117
Latest member
Aaagu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top