sportsguy
Finance wiz, Access hack
- Local time
- Today, 12:36
- Joined
- Dec 28, 2004
- Messages
- 363
so far, All examples have failed, and yet, I don't exactly know why. I have extracted data from a SQL Server onto a tab named DATA, the row count will be different each time, but the column count is fixed. I highlight the data and am trying to assign the highlighted range to the name PIVOTDATA for a pivotable range to dynamically adjust to the data range.
What am I missing?
What am I missing?
Code:
Sub RenameRange()
On Error GoTo Err_RenameRange
Dim LastRow As Long
Dim LastColumn As Long
Dim NamedRangeDynamic As Range
ActiveWorkbook.Names("PIVOTDATA").Delete
Worksheets("ACT").Activate
Set NamedRangeDynamic = ActiveSheet.Range("A1", ActiveSheet.Range("a1").End(xlDown).End(xlToRight)).Select
ThisWorkbook.Names.Add Name:="PIVOTDATA", RefersTo:=NamedRangeDynamic
Set NamedRangeDynamic = Nothing
Exit_RenameRange:
Exit Sub
Err_RenameRange:
If Err.Number = 1004 Then Resume Next
Debug.Print Err.Number & " - " & Err.Description
Resume Exit_RenameRange
End Sub