VBA, insert column in Excel table, range class failed

jcauteru

New Member
Joined
Jul 27, 2010
Messages
15
Hey all, I'm trying to select a table on a worksheet and insert a column in this table. It needs to be code because it will eventually be applied to many, many tables. I'm just trying to work out the reference.

Code:
Sub insert_col()
Dim sh As Worksheet
Set sh = Sheet3

sh.ListObjects("Table5").Range.Select 'Errors out
Selection.ListObject.ListColumns.Add Position:=3

End Sub

I get a "select method of range class failed" error. The problem is the sheet reference, I'm going to keep trying to figure it out but any help would be appreciated.

-Joe
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Have you tried without selecting?

Code:
Sub insert_col()
    Dim sh As Worksheet
    Set sh = Sheet3
    sh.ListObjects("Table5").ListColumns.Add Position:=3
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,594
Messages
6,179,795
Members
452,943
Latest member
Newbie4296

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top