Johnny Thunder
Well-known Member
- Joined
- Apr 9, 2010
- Messages
- 693
- Office Version
- 2016
- Platform
- MacOS
Hi Guys, working on a script to dynamically update a named range for my data to the last row when a report is ran and hitting a roadblock with my code.
I am getting an error on the code, most likely because the syntax is wrong so I was hoping someone may know how to do this.
I am using the Usedrange line to find the last active row in my workbook but its not working. My data currently goes to row 5000.
Any help is appreciated
I am getting an error on the code, most likely because the syntax is wrong so I was hoping someone may know how to do this.
I am using the Usedrange line to find the last active row in my workbook but its not working. My data currently goes to row 5000.
Any help is appreciated
Code:
Sub UpdateRanges()
Dim sht As Worksheet
Dim wb As Workbook
Dim nr As Name
Dim lastR As Long
lastR = sht.UsedRange.SpecialCells(xlCellTypeLastCell).Row
With ActiveWorkbook.Names("Data1")
.Name = "Data1"
.RefersTo = "=Query1!$A$14:$AC$" & lastR & """"
End With
End Sub