SamNew2Coding
New Member
- Joined
- Jun 15, 2020
- Messages
- 11
- Office Version
- 365
- Platform
- Windows
I am trying to create a named range for multiple sheets from a specific cell to the last row. What i currently have:
I have taken this mostly from other posts. I feel like i am close but it bugs when i run this line:
I need some way to return the wsName value.
Bonus: Most sheets it will be "A3:D" and LastRow but for two of them it will be "B3:D" & LastRow, Is there an easy way to have an extra dimension where i can tell it to use this variable for two of them or do i have to just have another loop for the two different sheets?
VBA Code:
Sub test123()
Dim wsName As Variant, ws As Worksheet, LastRow As Long
For Each wsName In Array("AA-CR", "AA-CP", "AAA-CR", "AAA-CP", "AAT-CP", "AAT-CR")
Set ws = Worksheets(wsName)
LastRow = ws.Cells.Find(What:="*", LookIn:=xlValues, SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
wsStringName = wsName
ws.Range("A3:D" & LastRow).Name = wsName
Next
End Sub
I have taken this mostly from other posts. I feel like i am close but it bugs when i run this line:
VBA Code:
ws.Range("B3:D" & LastRow).Name = wsName
I need some way to return the wsName value.
Bonus: Most sheets it will be "A3:D" and LastRow but for two of them it will be "B3:D" & LastRow, Is there an easy way to have an extra dimension where i can tell it to use this variable for two of them or do i have to just have another loop for the two different sheets?