Multiple Column Loop from wbA and copy/paste all data to 1 column on wkB

meisch

New Member
Joined
Oct 22, 2020
Messages
4
Office Version
  1. 2016
Platform
  1. Windows
Hello all,



I'm trying to create an array loop that goes through columns A1,D1,G1, J1 (Keeping the headers) from one workbook and paste all the data to one column (keeping cell formatting) on another workbook.

The data in the copied columns (A,D,G,J) will vary every time the macro runs so I'm not sure how to set up the initial array for this.

I think I have the destination ready with:

VBA Code:
Private Sub CommandButton2_Click()

Dim coV As Worksheet
Dim rr As Worksheet
Dim destLast As Long

Set coV = Workbooks("Cov19 Analysis.xlsm").Worksheets("Reruns To Pull")
Set rr = Workbooks("Rerun_new.xlsx").Worksheets("October")
destLast = rr.Cells(rr.Rows.Count, "A").End(xlUp).Offset(1).Row

?????? .Copy _
    rr.Range("A" & destLast)
End Sub

Any help would be much appreciated!
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Based on the narrative in the OP.
VBA Code:
Sub t()
Dim ary As Variant, i As Long
ary = Array("A", "D", "G", "J")
With ActiveSheet
    For i = LBound(ary) To UBound(ary)
        Intersect(.UsedRange, .Columns(ary(i))).Copy
        Workbooks(2).Sheets(1).Cells(Rows.Count, 1).End(xlUp)(2).PasteSpecial xlPasteValuesAndNumberFormats  'puts all in one column of wb 2
    Next
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,531
Messages
6,114,167
Members
448,554
Latest member
Gleisner2

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