Copy range to last used-column

bgonen

Active Member
Joined
Oct 24, 2009
Messages
264
I am trying to add a command of copy range B2:O2 (in ws; TMHP-PL) to range of P2:to last used column (also in TMHP-PL ws)
The last column used is actually shown on row 3
The procedure goes like this but I am only able to copy/paste partially:

Sub CopyPasteAcrossColumnsFINAL2()
Dim LR As Long, i As Long
Application.ScreenUpdating = False
With Sheets("structure")
LR = .Range("A" & Rows.Count).End(xlUp).Row
For i = 1 To LR
.Range("A" & i).Copy Destination:=Sheets("TMHP-PL").Cells(3, 14 * i - 12).Resize(, 13)
Next i
End With
Dim LC As Long
LC = Cells(3, Columns.Count).End(xlToLeft).Column
Range("B2:O2").Copy
Range(Cells(2, 16), Cells(2, LC)).PasteSpecial Paste:=xlPasteFormulas


End Sub
 

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
Maybe

Code:
Sub CopyPasteAcrossColumnsFINAL2()
Dim LR As Long, i As Long
Dim LC As Long
Application.ScreenUpdating = False
With Sheets("structure")
    LR = .Range("A" & Rows.Count).End(xlUp).Row
    For i = 1 To LR
        .Range("A" & i).Copy Destination:=Sheets("TMHP-PL").Cells(3, 14 * i - 12).Resize(, 13)
    Next i
End With
With Sheets("TMHP-PL")
    LC = .Cells(3, Columns.Count).End(xlToLeft).Column
    .Range("B2:O2").Copy
    .Cells(2, LC+1).PasteSpecial Paste:=xlPasteFormulas
End With
End Sub
 
Upvote 0
Strange,
The range B2:O2 is getting pasted starting on the last used column (GCG2)

But nothing get pasted between P2 forward (up to the last used column)
 
Upvote 0
Maybe something like this

Code:
Sub CopyPasteAcrossColumnsFINAL2()
Dim LR As Long, i As Long
Dim LC As Long, j As Long
Application.ScreenUpdating = False
With Sheets("structure")
    LR = .Range("A" & Rows.Count).End(xlUp).Row
    For i = 1 To LR
        .Range("A" & i).Copy Destination:=Sheets("TMHP-PL").Cells(3, 14 * i - 12).Resize(, 13)
    Next i
End With
With Sheets("TMHP-PL")
    LC = .Cells(3, Columns.Count).End(xlToLeft).Column
    .Range("B2:O2").Copy
    For j = 16 To LC + 1 Step 14
        .Cells(2, j).PasteSpecial Paste:=xlPasteFormulas
    Next j
End With
End Sub
 
Upvote 0
This is it Peter:)
I think I will go underground for a while after I bugged you so many times

Lots of thanks
Boaz
 
Upvote 0

Forum statistics

Threads
1,224,552
Messages
6,179,488
Members
452,917
Latest member
MrsMSalt

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