Out Of range Error with Find

Shiseiji

Board Regular
Joined
Oct 23, 2009
Messages
214
Office Version
  1. 2019
Platform
  1. Windows
I've used similar code in the past, but can't figure out what I'm missing. Troubleshooting I've reduced the find down to a single string and still get "Out of Range." Help is appreciated!
Some of the comments are notes to myself as to why code may be different than code I've used in the past.

VBA Code:
Sub MakeRanges_m()
   '
    Sheets("OHR Report").Activate
    '
    Dim LastCol             As Integer
    Dim LastRow             As Long
    Dim rng_HeaderRow       As Range
    Dim ThisWb              As Workbook
    Dim ThisWs              As Worksheet
    '
    Set ThisWb = ActiveWorkbook
    Set ThisWs = ActiveSheet
    '
    With ThisWb
    With ThisWs
    '
    LastRow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
    LastCol = Cells(1, Columns.Count).End(xlToLeft).Column
'    Range("A1", Cells(LastCol)).Name = "rng_HeaderRow" 'I don't understand why this doesn't work with a "DIM rng_HeaderRow As Long"  like "LastRow", but changed it to a named range
'    Range("A1", Cells(LastRow, LastCol)).Name = "rng_tbl"
'---Start create ranges---
    .Names.Add Name:="rng_HeaderRow", RefersTo:=Range("A1", Cells(LastCol))
'  Range("A1", Cells(LastCol)).Name = "rng_HeaderRow" wouldn't work, no idea why . . . 
'
    Set Rng = Range("rng_HeaderRow")
    With Rng
            .Find(What:="Primary TW Zip Code", LookAt:=xlAll, SearchOrder:=xlByRows, SearchDirection:=xlNext).Name = "c_p_zipcode"
    End With
   Cells(1, 1).Select
   Cells(1, 1).Activate
    End With 'ThisWs
    End With 'ThisWb
End Sub
TIA

Ron
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Very much so! I am so in debt to the members of this forum it's a struggle to pay it forward.
 
Upvote 0

Forum statistics

Threads
1,215,073
Messages
6,122,970
Members
449,095
Latest member
Mr Hughes

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