excelguru123
New Member
- Joined
- Jun 23, 2021
- Messages
- 6
- Office Version
- 2013
- Platform
- Windows
Hi all, I have a table with multiple columns and I am trying to select multiple columns using their names. Columns aren't necessarily adjacent to each other so I want to use column names to select them. Here is a code:
With wbMyWorkbook.Sheets("Sheet1").ListObjects("Table1")
.ListColumns("Name").Range.Select
.ListColumns("Address").Range.Select
.ListColumns("City").Range.Select
End With
Using this works but it doesn't select ALL of the columns "Name", "Address", & "City". Instead, it will select one column at a time. This is just 3 columns as an example but I have around 15 columns I want selected. To make it cleaner I tried to use an array in .ListColumns() but it takes a single object only. How can I make this work? Thanks in advance.
With wbMyWorkbook.Sheets("Sheet1").ListObjects("Table1")
.ListColumns("Name").Range.Select
.ListColumns("Address").Range.Select
.ListColumns("City").Range.Select
End With
Using this works but it doesn't select ALL of the columns "Name", "Address", & "City". Instead, it will select one column at a time. This is just 3 columns as an example but I have around 15 columns I want selected. To make it cleaner I tried to use an array in .ListColumns() but it takes a single object only. How can I make this work? Thanks in advance.