Referencing columns by number in macro?

jackjones123

New Member
Joined
Sep 26, 2019
Messages
4
Hi,

I'm looking to pull the contents of multiple workbooks into one, and found this old thread, the first reply works perfectly:
https://www.mrexcel.com/forum/excel...file-folder-copy-data-into-open-workbook.html

However, that macro populates the summary sheet top-to-bottom whereas I want to populate it left-to-right, ie a new column for each workbook. So I need to reference the column by number.

I've tried changing rowTarget to iCol and changing ".Range("A" & rowTarget).Value = wsSource.Range("C2").Value" to ".Range(iCol & 1).Value = wsSource.Range("C2").Value" but not only does not populate, the macro just seems to open the first workbook and then do nothing. I've tried a few different variations but I'm getting nowhere.

Can anyone tell me what I need to do to make this work?
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Hi & welcome to MrExcel.

What cells do you want copy & where should they be copied to?
 
Upvote 0
Hi. If you want to use a column number then maybe try cells method. eg for:

Code:
.Range("C2")

you could write

Code:
.Cells(2,3)
 
Upvote 0

Forum statistics

Threads
1,215,339
Messages
6,124,370
Members
449,155
Latest member
ravioli44

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