Copy One column Multiple times based on a value in one specific cell

kmamdouh

New Member
Joined
Feb 19, 2019
Messages
5
Hello Everyone.

I would like to know if there is a way to copy an entire column and insert it "X" number of times where "X" is a value in a specific cell

For Example

I want to copy the column C:C and insert it to the right, 4 times, where "4" is the value in the cell "A1".

Would you please help writing this code

Thanks
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Hi & welcome to MrExcel.
How about
Code:
Sub kmamdouh()
   Columns(3).Copy
   Columns(3).Resize(, Range("A1").Value).Insert
End Sub
 
Upvote 0
Code:
Sub t()
With ActiveSheet
    .Range("G:G").Copy
    .Range("H:H").Resize(, Range("A1").Value).Insert
End With
End Sub
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0
I'm so sorry, but I've one more question, how to make it automatic updated every time I insert the number in Cell A1
as example if I put number "4" in the cell A1, then the macro will work automatically and insert the 4 copied columns
 
Upvote 0
This needs to go in the relevant sheet module
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.Address(0, 0) = "A1" Then
      Columns(3).Copy
      Columns(3).Resize(, Range("A1").Value).Insert
   End If
End Sub
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,992
Messages
6,122,631
Members
449,095
Latest member
bsb1122

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