VBA Copy adjacent AND non-adjacent named table columns

Bleed_Air

New Member
Joined
Aug 3, 2024
Messages
2
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
  2. MacOS
Hi everyone.

I have the following code which copies the named contiguous columns from the table, and I have other code which pastes the copied data onto another sheet. It works like a charm:

VBA Code:
Range("Table1[[#All],[Column_1]:[Column_4]]").Copy

I want to add a couple of non-adjacent columns to the copy function; let's call them Column_6 and Column_9, so that I end up with something like this (which obviously doesn't work):

VBA Code:
Range("Table1[[#All],[Column_1]:[Column_4],[Column_6],[Column_9]]").Copy

Is someone able to tell me what the symbol and formatting should be, for the code that goes between [Column_4] and [Column_6]? I've tried using @, & and commas as the separator (as suggested from another forum) and they didn't work. I don't know a lick about VBA and I picked up this code from another location which I now can't find, so that brings me here. Pointing me to a good source example is also appreciated, because I have Google'd to the ends of the earth and can't find the one I originally used.

Many thanks :)
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Use Union to combine the ranges:

VBA Code:
    Union(Range("Table1[[#All],[Col 1]:[Col 3]]"), Range("Table1[[#All],[Col 5]]"), Range("Table1[[#All],[Col 9]]")).Copy
 
Upvote 1
Solution
Use Union to combine the ranges:

VBA Code:
    Union(Range("Table1[[#All],[Col 1]:[Col 3]]"), Range("Table1[[#All],[Col 5]]"), Range("Table1[[#All],[Col 9]]")).Copy
You, my friend, are a life saver! Thank you so much for providing the answer I was looking for.
 
Upvote 0

Forum statistics

Threads
1,223,884
Messages
6,175,175
Members
452,615
Latest member
bogeys2birdies

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