Hello,
I'm trying to set a dynamic variable using a Tables HeaderRowRange.
I figured if I can select the range using ActiveSheet.ListObjects(1).HeaderRowRange.Select that I could then store that selected range into a Range variable.
I was hoping to get a range of A2:J2 in the active table, but when using the MsgBox to output the variable value, I get the following Run-time error:
I'm trying to find a dynamic way of setting this value so this code will work in other tables and sheets.
Any advice would be greatly appreciated.
I'm trying to set a dynamic variable using a Tables HeaderRowRange.
I figured if I can select the range using ActiveSheet.ListObjects(1).HeaderRowRange.Select that I could then store that selected range into a Range variable.
VBA Code:
Sub SetRange()
ActiveSheet.ListObjects(1).HeaderRowRange.Select 'Select table Header Row
Dim header As Range
Set header = Range(Selection.Address)
MsgBox header
End Sub
I'm trying to find a dynamic way of setting this value so this code will work in other tables and sheets.
Any advice would be greatly appreciated.