VBA Code to copy range based on value

Corleone

Well-known Member
Joined
Feb 2, 2003
Messages
841
Office Version
  1. 365
I would like to put some code into my spreadsheet do that it copies a range into columns based on the value in row 1 of each column

I hacve a tab entitled "TABLES"
Column C contains a range of data (c3:c204)
Columns D > EL the columns are numbered 2>140 in row 1

Row2 downwards is all blank in columns D>EL (Only column C has data in it)

I would like the code to copy the range in column C (c3:c204) into any column where the value in row 1 is equal or less than the value which is
located in a separate TAB "COVER Sheet" cell 14

thanks
 

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
Corleone,

This code assumes the value on the tab "COVER Sheet" is in cell A14. Give it a try.

Code:
Option Explicit


Sub CopyColumn()
Dim chkval As Integer
Dim i As Integer
chkval = Sheets("Cover Sheet").Range("A14")


For i = 2 To chkval
    Sheets("Tables").Range(Cells(3, i + 2), Cells(204, i + 2)).Value = Sheets("Tables").Range("C3:C204").Value
Next i


End Sub
 
Upvote 0
Thanks for this Frank - how would I change it so that it copies the formulas rather than the values
 
Upvote 0
Okay, I've modified the code to just copy what is in Column C.

Code:
Option Explicit


Sub CopyColumn()
Dim chkval As Integer
Dim i As Integer
chkval = Sheets("Cover Sheet").Range("A14")


For i = 2 To chkval
    Sheets("Tables").Range("C3:C204").Copy Destination:=Sheets("Tables").Range(Cells(3, i + 2), Cells(204, i + 2))
Next i


End Sub
 
Upvote 0

Forum statistics

Threads
1,214,870
Messages
6,122,019
Members
449,060
Latest member
LinusJE

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