Twollaston
Board Regular
- Joined
- May 24, 2019
- Messages
- 241
I'm trying to create a macro that sets up my reports with a header and spaces above and before the data
Essentially what I want to do is add a column in the front of my data, add 6 Rows above my data, turn gridlines off, and open my workbook that contains my header and copy and paste it into the report.
I created a macro to do it but i'm having issues with the pasting portion. All the rows columns and gridlines work fine. It opens the workbook with the header and it copies it, but i don't know how to call back the active report. I tried to create a variable for the original report sheet so I can call back to it when i need to paste, but it's not working for me. Anyone that can help me amend this slightly so that it will work?
Note: The header workbook will always be in the same path with the same name, but the original report I'm creating will never have the same name or path
What I have so far:
Essentially what I want to do is add a column in the front of my data, add 6 Rows above my data, turn gridlines off, and open my workbook that contains my header and copy and paste it into the report.
I created a macro to do it but i'm having issues with the pasting portion. All the rows columns and gridlines work fine. It opens the workbook with the header and it copies it, but i don't know how to call back the active report. I tried to create a variable for the original report sheet so I can call back to it when i need to paste, but it's not working for me. Anyone that can help me amend this slightly so that it will work?
Note: The header workbook will always be in the same path with the same name, but the original report I'm creating will never have the same name or path
What I have so far:
Code:
Sub AddHeaderAndRowsAndColumn()
OrigWork = ThisWorkbook.ActiveSheet.Name
'
Columns("A:A").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Rows("1:1").Select
Selection.Insert Shift:=xlDown
Selection.Insert Shift:=xlDown
Selection.Insert Shift:=xlDown
ActiveWindow.DisplayGridlines = False
Workbooks.Open Filename:= _
"W:\Dealer Sales Reporting Group\Wesley\Report Header.xlsx"
Rows("2:3").Select
Selection.Copy
OrigWork.Activate
ActiveSheet.Rows("2:3").Select
Selection.Paste
Windows("Report Header.xlsx").Activate
ActiveWindow.Close
End Sub
Last edited: