Appending data dynamically to sheet

flaaron

New Member
Joined
Jul 5, 2011
Messages
5
I have a series of large spreadsheets including thousands of columns. I want to be able to search through all columns and pull out certain columns and move those columns to another sheet for processing.

I do this currently by using the WorksheetFunction.Match function to match and store column positions and then copy the columns as shown below:

Code:
'Find the columns I want
esxtime1 = WorksheetFunction.Match("(PDH-CSV 4.0) (EDT)(0)", Rows("1:1"), 0)
counter1 = WorksheetFunction.Match("\\hcsesxicore?\Physical Cpu Load\Cpu Load (1 Minute Avg)", Rows("1:1"), 0)
.
.(shortened for brevity sake)

'Copy the columns to another sheet
Sheets(orgsheet).Columns(esxtime1).Copy Destination:=Sheets("Pivot_Source").Range("A1")
Sheets(orgsheet).Columns(counter1).Copy Destination:=Sheets("Pivot_Source").Range("B1")
.
.(shortened for brevity sake)
My desire is to be able to copy the data into the first empty column instead of having to statically map it because if I have to change the columns I want, I have to redefine the mappings in the copy code.

Ideally I want to throw the copy operations into a For loop, but looking to solve the copy appending issue first.

Thanks!
~Aaron
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
To copy into the next empty column:

Code:
Sheets(orgsheet).Columns(esxtime1).Copy Destination:=Sheets("Pivot_Source").Cells(1, Sheets("Pivot_Source").Columns.Count).End(xlToLeft).Offset(,1)
 
Upvote 0

Forum statistics

Threads
1,224,506
Messages
6,179,158
Members
452,892
Latest member
yadavagiri

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