Select multiple columns, copy and paste in the next free colum

cbprado

New Member
Joined
Oct 26, 2018
Messages
10
Saw many different formulas for selecting cells etc but couldnt find an answer to my question:

a) I need to select the whole Columns A, B an C (lets say), n have it copied to D (that is free). Then the contents will be cpied to D, E, F. Next time I ru the script, it must copy ABC and paste to GHI so on...

b) Next step would be insert the number of instances of ABC to the next available columns (like question (a) above)

Any hints?

Thank you all
 
Last edited by a moderator:

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Sub prado()
Dim z As String, x As Integer, y As Integer
y = Cells(1, Columns.Count).End(xlToLeft).Column
x = Cells(Rows.Count, 1).End(xlUp).Row
If y <= 26 Then
z = Chr(y + 64)
Else
z = Chr(y / 26 + 64) & Chr((y Mod 26) + 64)
End If
Range("A1:C" & x).Copy
Range(z & 1).PasteSpecial
MsgBox "complete"
End Sub
These codes successively copy col A to C to the next available column till ZZ.
Ravi shakar
 
Upvote 0
@ravishankar
Your code will copy to the wrong column. Also when posting code please use code tags (the # icon in the reply window), not quote tags. Cheers
@cbprado
This will copy cols A:C to the next free column
Code:
Sub CopyCols()
   Dim Nc As Long
   Nc = Cells(1, Columns.Count).End(xlToLeft).Offset(, 1).Column
   Range("A:C").Copy Cells(1, Nc)
End Sub
and I'm not sure what you mean with part b
 
Upvote 0
A BIG than you! it works beautifully...

he scn question (b) was relate to automatizing the copy of N instances rather than run the macro N times in order to get N copies. For instance, I need to copy A:C 10 times on the following free columns (would like to inform the nubr of instnces)

tks


@ravishankar
Your code will copy to the wrong column. Also when posting code please use code tags (the # icon in the reply window), not quote tags. Cheers
@cbprado
This will copy cols A:C to the next free column
Code:
Sub CopyCols()
   Dim Nc As Long
   Nc = Cells(1, Columns.Count).End(xlToLeft).Offset(, 1).Column
   Range("A:C").Copy Cells(1, Nc)
End Sub
and I'm not sure what you mean with part b
 
Upvote 0
How about
Code:
Sub CopyCols()
   Dim Nc As Long
   Dim Qty As Variant
   Nc = Cells(1, Columns.Count).End(xlToLeft).Offset(, 1).Column
   Qty = InputBox("Enter the number of copies to be made")
   If IsNumeric(Qty) Then Range("A:C").Copy Cells(1, Nc).Resize(, 3 * Qty)
End Sub
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,279
Members
449,075
Latest member
staticfluids

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