jccarrenod
New Member
- Joined
- May 13, 2015
- Messages
- 2
Hi guys,
Brand new member and first post, this is also my first time playing with macros/vba and have searched the web for two days now and have come up empty handed; I hope you can help.
I have a workbook (Master Production Report) where I have the following tabs
Tab 1 "Control": Here I want an array of buttons that users can click on to execute the macros loaded in the rest of the workbook
Tab 2 "Charts & Reports": Here I want a series of pivot charts created based on the selection the user makes on Tab 1
Tab 3 "data_rev": Here I have all the raw data used to create the reports on Tab 2. Macros would be executed upon this data based on the selections made on Tab 1
I am still building this report so I may need more raw data sheets but in essence this is what I need. What I've done so far is create a macro that would format the raw data so that it can be used to create pivot reports, this formatting is basic (setting titles to all rows, etc) and I think it runs ok. My next step was creating a button on Tab 1 to execute this macro which would format the data on Tab 3, and here is where I got stuck and could not make it work.
My code for the macro on Tab 3 as follows:
Sub Accelerate_formatting()
'
' Accelerate_formatting Macro
' Format accelerate reports to work with master report
'
'
ActiveWindow.SmallScroll Down:=42
Range("F52:G52").Select
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlCenter
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = True
End With
Selection.UnMerge
Range("F52").Select
Selection.Copy
Range("G52").Select
ActiveSheet.Paste
Range("F52").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "Hotel ID"
Range("K52:L52").Select
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlCenter
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = True
End With
Selection.UnMerge
Range("K52").Select
Selection.Copy
Range("L52").Select
ActiveSheet.Paste
Range("K52").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "Customer ID"
Range("N52:O52").Select
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlCenter
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = True
End With
Selection.UnMerge
Range("N52").Select
ActiveCell.FormulaR1C1 = "Interface"
Range("O52").Select
ActiveSheet.Paste
Range("R51").Select
ActiveCell.FormulaR1C1 = "CFYTD"
Range("R50").Select
ActiveCell.FormulaR1C1 = "Roomnights (Service) CFYTD"
Range("U50").Select
ActiveCell.FormulaR1C1 = "TTV CFYTD"
Range("X50").Select
ActiveCell.FormulaR1C1 = "Cost of Sales CFYTD"
Range("AA50").Select
ActiveCell.FormulaR1C1 = "Operating Margin CFYTD"
Range("S51").Select
ActiveCell.FormulaR1C1 = "LFYTD"
Range("S50").Select
ActiveCell.FormulaR1C1 = "Roomnights (Service) LFYTD"
Range("V50").Select
ActiveCell.FormulaR1C1 = "TTV LFYTD"
Range("Y50").Select
ActiveCell.FormulaR1C1 = "Cost of Sales LFYTD"
Range("AB50").Select
ActiveCell.FormulaR1C1 = "Operating Margin LFYTD"
Range("T51").Select
ActiveCell.FormulaR1C1 = "Total LFY"
Range("T50").Select
ActiveCell.FormulaR1C1 = "Roomnights (Service) Total LFY"
Range("W50").Select
ActiveCell.FormulaR1C1 = "TTV Total LFY"
Range("Z50").Select
ActiveCell.FormulaR1C1 = "Cost of Sales Total LFY"
Range("AC50").Select
ActiveCell.FormulaR1C1 = "Operating Margin Total LFY"
Range("R50:AC50").Select
Selection.Cut
Range("R52").Select
ActiveSheet.Paste
Rows("50:51").Select
Range("Q51").Activate
Selection.Delete Shift:=xlUp
Range("A50").Select
End Sub
After trying several different options this is the latest code I have for the button on Tab 1:
Sub CommandButton1_Click()
Worksheet("data_rev").Range("F52:G52").Select
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlCenter
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = True
End With
Selection.UnMerge
Range("F52").Select
Selection.Copy
Range("G52").Select
ActiveSheet.Paste
Range("F52").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "Hotel ID"
Range("K52:L52").Select
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlCenter
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = True
End With
Selection.UnMerge
Range("K52").Select
Selection.Copy
Range("L52").Select
ActiveSheet.Paste
Range("K52").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "Customer ID"
Range("N52:O52").Select
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlCenter
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = True
End With
Selection.UnMerge
Range("N52").Select
ActiveCell.FormulaR1C1 = "Interface"
Range("O52").Select
ActiveSheet.Paste
Range("R51").Select
ActiveCell.FormulaR1C1 = "CFYTD"
Range("R50").Select
ActiveCell.FormulaR1C1 = "Roomnights (Service) CFYTD"
Range("U50").Select
ActiveCell.FormulaR1C1 = "TTV CFYTD"
Range("X50").Select
ActiveCell.FormulaR1C1 = "Cost of Sales CFYTD"
Range("AA50").Select
ActiveCell.FormulaR1C1 = "Operating Margin CFYTD"
Range("S51").Select
ActiveCell.FormulaR1C1 = "LFYTD"
Range("S50").Select
ActiveCell.FormulaR1C1 = "Roomnights (Service) LFYTD"
Range("V50").Select
ActiveCell.FormulaR1C1 = "TTV LFYTD"
Range("Y50").Select
ActiveCell.FormulaR1C1 = "Cost of Sales LFYTD"
Range("AB50").Select
ActiveCell.FormulaR1C1 = "Operating Margin LFYTD"
Range("T51").Select
ActiveCell.FormulaR1C1 = "Total LFY"
Range("T50").Select
ActiveCell.FormulaR1C1 = "Roomnights (Service) Total LFY"
Range("W50").Select
ActiveCell.FormulaR1C1 = "TTV Total LFY"
Range("Z50").Select
ActiveCell.FormulaR1C1 = "Cost of Sales Total LFY"
Range("AC50").Select
ActiveCell.FormulaR1C1 = "Operating Margin Total LFY"
Range("R50:AC50").Select
Selection.Cut
Range("R52").Select
ActiveSheet.Paste
Rows("50:51").Select
Range("Q51").Activate
Selection.Delete Shift:=xlUp
Range("A50").Select
End Sub
However it has not worked. I've tried several different options to select the sheet (workbook.sheet.select / sheet.select / worksheet.select) and nothing has worked. The latest error message I get is "Compile error: Sub or Function not defined"
I am working on Excel 2010 version 14 (32 bit) running on Windows 7 Professional (in case this is relevant).
I am doing this to try to modify a report my company created to better suit the needs of my region, however, the macro in their report is protected so I cant see the code. I will probably have many more questions as I go along so appreciate any help in advance.
Cheers!
Brand new member and first post, this is also my first time playing with macros/vba and have searched the web for two days now and have come up empty handed; I hope you can help.
I have a workbook (Master Production Report) where I have the following tabs
Tab 1 "Control": Here I want an array of buttons that users can click on to execute the macros loaded in the rest of the workbook
Tab 2 "Charts & Reports": Here I want a series of pivot charts created based on the selection the user makes on Tab 1
Tab 3 "data_rev": Here I have all the raw data used to create the reports on Tab 2. Macros would be executed upon this data based on the selections made on Tab 1
I am still building this report so I may need more raw data sheets but in essence this is what I need. What I've done so far is create a macro that would format the raw data so that it can be used to create pivot reports, this formatting is basic (setting titles to all rows, etc) and I think it runs ok. My next step was creating a button on Tab 1 to execute this macro which would format the data on Tab 3, and here is where I got stuck and could not make it work.
My code for the macro on Tab 3 as follows:
Sub Accelerate_formatting()
'
' Accelerate_formatting Macro
' Format accelerate reports to work with master report
'
'
ActiveWindow.SmallScroll Down:=42
Range("F52:G52").Select
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlCenter
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = True
End With
Selection.UnMerge
Range("F52").Select
Selection.Copy
Range("G52").Select
ActiveSheet.Paste
Range("F52").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "Hotel ID"
Range("K52:L52").Select
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlCenter
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = True
End With
Selection.UnMerge
Range("K52").Select
Selection.Copy
Range("L52").Select
ActiveSheet.Paste
Range("K52").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "Customer ID"
Range("N52:O52").Select
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlCenter
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = True
End With
Selection.UnMerge
Range("N52").Select
ActiveCell.FormulaR1C1 = "Interface"
Range("O52").Select
ActiveSheet.Paste
Range("R51").Select
ActiveCell.FormulaR1C1 = "CFYTD"
Range("R50").Select
ActiveCell.FormulaR1C1 = "Roomnights (Service) CFYTD"
Range("U50").Select
ActiveCell.FormulaR1C1 = "TTV CFYTD"
Range("X50").Select
ActiveCell.FormulaR1C1 = "Cost of Sales CFYTD"
Range("AA50").Select
ActiveCell.FormulaR1C1 = "Operating Margin CFYTD"
Range("S51").Select
ActiveCell.FormulaR1C1 = "LFYTD"
Range("S50").Select
ActiveCell.FormulaR1C1 = "Roomnights (Service) LFYTD"
Range("V50").Select
ActiveCell.FormulaR1C1 = "TTV LFYTD"
Range("Y50").Select
ActiveCell.FormulaR1C1 = "Cost of Sales LFYTD"
Range("AB50").Select
ActiveCell.FormulaR1C1 = "Operating Margin LFYTD"
Range("T51").Select
ActiveCell.FormulaR1C1 = "Total LFY"
Range("T50").Select
ActiveCell.FormulaR1C1 = "Roomnights (Service) Total LFY"
Range("W50").Select
ActiveCell.FormulaR1C1 = "TTV Total LFY"
Range("Z50").Select
ActiveCell.FormulaR1C1 = "Cost of Sales Total LFY"
Range("AC50").Select
ActiveCell.FormulaR1C1 = "Operating Margin Total LFY"
Range("R50:AC50").Select
Selection.Cut
Range("R52").Select
ActiveSheet.Paste
Rows("50:51").Select
Range("Q51").Activate
Selection.Delete Shift:=xlUp
Range("A50").Select
End Sub
After trying several different options this is the latest code I have for the button on Tab 1:
Sub CommandButton1_Click()
Worksheet("data_rev").Range("F52:G52").Select
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlCenter
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = True
End With
Selection.UnMerge
Range("F52").Select
Selection.Copy
Range("G52").Select
ActiveSheet.Paste
Range("F52").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "Hotel ID"
Range("K52:L52").Select
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlCenter
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = True
End With
Selection.UnMerge
Range("K52").Select
Selection.Copy
Range("L52").Select
ActiveSheet.Paste
Range("K52").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "Customer ID"
Range("N52:O52").Select
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlCenter
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = True
End With
Selection.UnMerge
Range("N52").Select
ActiveCell.FormulaR1C1 = "Interface"
Range("O52").Select
ActiveSheet.Paste
Range("R51").Select
ActiveCell.FormulaR1C1 = "CFYTD"
Range("R50").Select
ActiveCell.FormulaR1C1 = "Roomnights (Service) CFYTD"
Range("U50").Select
ActiveCell.FormulaR1C1 = "TTV CFYTD"
Range("X50").Select
ActiveCell.FormulaR1C1 = "Cost of Sales CFYTD"
Range("AA50").Select
ActiveCell.FormulaR1C1 = "Operating Margin CFYTD"
Range("S51").Select
ActiveCell.FormulaR1C1 = "LFYTD"
Range("S50").Select
ActiveCell.FormulaR1C1 = "Roomnights (Service) LFYTD"
Range("V50").Select
ActiveCell.FormulaR1C1 = "TTV LFYTD"
Range("Y50").Select
ActiveCell.FormulaR1C1 = "Cost of Sales LFYTD"
Range("AB50").Select
ActiveCell.FormulaR1C1 = "Operating Margin LFYTD"
Range("T51").Select
ActiveCell.FormulaR1C1 = "Total LFY"
Range("T50").Select
ActiveCell.FormulaR1C1 = "Roomnights (Service) Total LFY"
Range("W50").Select
ActiveCell.FormulaR1C1 = "TTV Total LFY"
Range("Z50").Select
ActiveCell.FormulaR1C1 = "Cost of Sales Total LFY"
Range("AC50").Select
ActiveCell.FormulaR1C1 = "Operating Margin Total LFY"
Range("R50:AC50").Select
Selection.Cut
Range("R52").Select
ActiveSheet.Paste
Rows("50:51").Select
Range("Q51").Activate
Selection.Delete Shift:=xlUp
Range("A50").Select
End Sub
However it has not worked. I've tried several different options to select the sheet (workbook.sheet.select / sheet.select / worksheet.select) and nothing has worked. The latest error message I get is "Compile error: Sub or Function not defined"
I am working on Excel 2010 version 14 (32 bit) running on Windows 7 Professional (in case this is relevant).
I am doing this to try to modify a report my company created to better suit the needs of my region, however, the macro in their report is protected so I cant see the code. I will probably have many more questions as I go along so appreciate any help in advance.
Cheers!