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.
TIA
Ron
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
Ron