Copy from Array and paste to different array

AbdulkareemAlhassni

New Member
Joined
Nov 16, 2018
Messages
41
Hi guys,

what am i doing wrong here ?

Private Sub CommandButton1_Click99()
Dim LR As Long, i As Long, cls
cls = Array("B2", "D2", "C2")


With Sheets("Sheet2")
LR = WorksheetFunction.Max(2, .Range(Array("H1", "K1", "Z1")))
For i = LBound(cls) To UBound(cls)
Range(cls(i)).Copy Destination:=.Cells(LR, i + 1)
Next i
End With
End Sub


Code:
Private Sub CommandButton1_Click99()
Dim LR As Long, i As Long, cls
cls = Array("B2", "D2", "C2")


With Sheets("Sheet2")
    LR = WorksheetFunction.Max(2, .Range(Array("H1", "K1", "Z1")))
    For i = LBound(cls) To UBound(cls)
        Range(cls(i)).Copy Destination:=.Cells(LR, i + 1)
    Next i
End With
End Sub


I want to copy from specified cells and paste to specified cells
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Maybe
Code:
    LR = WorksheetFunction.Max(2, .Range("H1, K1, Z1"))

its not doing what i want,

Code:
Private Sub CommandButton1_Click99()Dim LR As Long, i As Long, cls
cls = Array("B2", "D2", "C2")




With Sheets("Sheet2")
    For i = LBound(cls) To UBound(cls)
        Range(cls(i)).Copy Destination:=.Cells("F2,G2,H2")
    Next i
End With
End Sub


i want to copy B2 and D2 and C2 from the first sheet

to another sheet cells H2, K2, Z2
 
Last edited:
Upvote 0
In that case try
Code:
Private Sub CommandButton1_Click99()
Dim LR As Long, i As Long, cls
cls = Array("B2", "F2", "D2", "G2", "C2", "H2")




With Sheets("Sheet2")
    For i = LBound(cls) To UBound(cls) Step 2
        Range(cls(i)).Copy Destination:=.Range(cls(i + 1))
    Next i
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,557
Messages
6,114,291
Members
448,564
Latest member
ED38

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