I would like to create a table with an unknown range. I currently have the following.
Sub Button2_Click()
Dim r As Range
Set r = Worksheets("Sheet2").Range("A1").CurrentRegion
Worksheets("Sheet2").ListObjects.Add(xlSrcRange, Range("A1:B4"), xlYes).Name = "MyTable"
End Sub
An example of the Excel data on Sheet 2.
Job Position Time
V1 10
V2 11
V3 12
What I have above does not work. It will work if Range() has Range("A1:B4"). I thought that if I defined r as a range, it will substitute "A1:B4" in Range().
I receive a Run Time Error 1004 and Method Range of Object Global Failed.
Sub Button2_Click()
Dim r As Range
Set r = Worksheets("Sheet2").Range("A1").CurrentRegion
Worksheets("Sheet2").ListObjects.Add(xlSrcRange, Range("A1:B4"), xlYes).Name = "MyTable"
End Sub
An example of the Excel data on Sheet 2.
Job Position Time
V1 10
V2 11
V3 12
What I have above does not work. It will work if Range() has Range("A1:B4"). I thought that if I defined r as a range, it will substitute "A1:B4" in Range().
I receive a Run Time Error 1004 and Method Range of Object Global Failed.