Copy values horizontally

bgonen

Active Member
Joined
Oct 24, 2009
Messages
264
I have lots of values starting A1 down

Trying to copy value in A1 to the range P3:R3

Then trying to copy value A2 to the range T3:V3

(notice I need to keep a blank cell (in this case S3)

Thanks
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Code:
Sub test()
Dim x As Long, y As Long
y = 2
For x = 1 To Range("A" & Range("A" & Rows.Count).End(xlUp).Row) Step 2
    y = y + 1
    If Range("A" & x) = "" Then
        Range("P" & y).Resize(, 3).ClearContents
    Else
        Range("P" & y).Resize(, 3) = Range("A1").Offset(x - 1)
    End If
    
    If Range("A" & x + 1) = "" Then
        Range("T" & y).Resize(, 3).ClearContents
    Else
        Range("T" & y).Resize(, 3) = Range("A1").Offset(x)
    End If
Next x
End Sub
 
Upvote 0
Try

Code:
Sub test()
Dim LR As Long, i As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = 1 To LR
    Range("A" & i).Copy Destination:=Cells(3, 4 * i + 12).Resize(, 3)
Next i
End Sub
 
Upvote 0
Peter,
Your command works perfectly but I don't understand how column P is determined as destination,,, (trying to understand your code since actually I need to start at Q3 (not P3,,as I wrongly mentioned earlier).

Thanks bg

Hotpepper,
Thanks for your quick feedback I will try to understand and work with your commands later.
 
Upvote 0
Column P is Column 16

So first time through the loop 4*1+12=16
Second time throught the looop 4*2+12=20
etc.
 
Upvote 0
To start at Q, change the 12 to 13:

Code:
Sub test()
Dim LR As Long, i As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = 1 To LR
    Range("A" & i).Copy Destination:=Cells(3, 4 * i + 13).Resize(, 3)
Next i
End Sub
 
Upvote 0
Sorry, I got excited too early;
when I ran the commands (below) I was hoping to change the destination (to horizontally 13 columns) but I keep getting 4 columns get copied and then the next value get copied over the next four columns.

Also, I was hoping to get one blank column (with no value),,

Sub CopyPasteAcrossColumnsFINAL()
Dim LR As Long, i As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = 1 To LR
Range("A" & i).Copy Destination:=Cells(3, 4 * i + 13).Resize(, 13) '4*1 + 13 = Col Q
Next i
End Sub
 
Upvote 0
Try

Code:
Sub CopyPasteAcrossColumnsFINAL()
Dim LR As Long, i As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = 1 To LR
    Range("A" & i).Copy Destination:=Cells(3, 14 * i + 3).Resize(, 13)
Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,606
Messages
6,179,866
Members
452,948
Latest member
UsmanAli786

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