Macro to copy columns from one sheet to another using coloumn letter above header?

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,194
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone,

I have a Sheet called "Reports 1"
and another called "Subs RR"

i want to copy coulmns from "Subs RR" to "Reports 1" but the sheets dont have the same data in the same columns so i need to pull it in one column at a time.
so heres what i'm looking for

Sheets "Reports 1" has headers in Row 20 so everything gets pasted below starting in row 21

"Subs RR" has headers in row 10 so we are coping from 11 to last row and pasting into Sheets "Reports 1" row 21 (and column?)

now in Sheets "Reports 1" Row 18 i have the Column letter that i want to copy from
so if A18 ="L" then i'm look to copy sheets "Subs RR" range ("L11 to L & lastrow") to Sheets "Reports 1" A21) and so on

the columns with headers in Sheets "Reports 1" are A to CZ and i need the macro to be able to do all of these,

hopes thats clear, please help if you can

Thanks

Tony
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Hi. Try:
VBA Code:
Sub CopyPasteData()
 Dim rngCol As Range, LastRow As Long
  With Sheets("Reports 1")
   For Each rngCol In .Range("A18:CZ18")
    LastRow = Sheets("Subs RR").Cells(Rows.Count, rngCol.Value).End(3).Row
     Sheets("Subs RR").Range(rngCol.Value & 11).Resize(LastRow - 10).Copy .Cells(21, rngCol.Column)
   Next rngCol
  End With
End Sub
 
Upvote 0
Thank you Osvaldo,
this is great, but one thing i forgot to add is not every cell in Range("A18:CZ18") has a Letter in it some are blank, i only want to do it on the non blank ones?
can this be easily added?

thanks

Tony
 
Upvote 0
Hi, Tony.
I considered that blank cells are really empty cells and not with formulas that return blank.

Please, change the line as below:
For Each rngCol In .Range("A18:CZ18").SpecialCells(xlConstants, 2)
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,718
Members
448,986
Latest member
andreguerra

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