Copy and paste with array

Jesslynn

New Member
Joined
Jun 16, 2015
Messages
17
Can anybody help me edit? I want to copy from column to another workbook column using array.
The range inside the array is the Alphabet of the column i want to copy/paste.
The bold part is the one where I'm stuck at..




Code:
Sub setting2()
Dim wb As ThisWorkbook


Dim here As Workbook
Dim there As Workbook


Dim source() As Variant


Dim log() As Variant


Dim LastRowHere() As Integer
Dim LastRowThere() As Integer






'Open both workbooks first:
Set here = Workbooks.Open("C:\Users\hello\Desktop\G's\Setting2.xlsm")
Set there = Workbooks.Open("C:\Users\hello\Desktop\G's\Setting3.xlsm")




Windows("Setting.xlsm").Activate
source() = Array(Sheets("Sheet1").Range("E11"), Range("E12"), Range("E13"), Range("E14"), Range("E15"), Range("E16"), Range("E17").Value)


Windows("Setting.xlsm").Activate
log() = Array(Sheets("Sheet1").Range("J11"), Range("J12"), Range("J13"), Range("J14"), Range("J15"), Range("J16"), Range("J17").Value)


[B]Windows("Setting2.xlsm").Activate
LastRowHere() = Array(Sheets("Sheet1").Rows.Count, source().End(xlUp).Row)[/B]


Windows("Setting3.xlsm").Activate
LastRowThere() = Array(Sheets("Sheet1").Rows.Count, log()).End(xlUp).Row


For i = 1 To LastRowHere()


LastRowThere(1) = there.Sheets("Sheet1").Cells(Sheets("Sheet1").Rows.Count, log(1)).End(xlUp).Row


    For k = 1 To LastRowThere()
    
        'here.Sheets("Sheet1").Cells(i, k).Copy Destination:=there.Sheets("Sheet1").Cells(i, k)
here.Sheets("Sheet1").Rows(i).Columns(source(1)).Copy Destination:=there.Sheets("Sheet1").Rows(k + 1).Columns(log(1))


    Next k
Next i


End Sub
 
Last edited:

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

Forum statistics

Threads
1,215,338
Messages
6,124,356
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