I haven't spent much time recording macros before, at least not successfully.
I recorded one recently but it doesn't work properly. It does seem to do about 70% of what I want it to do but then I get that runtime error and it gives the option to debug. Can anyone advise what's happening and how to fix it?
I recorded one recently but it doesn't work properly. It does seem to do about 70% of what I want it to do but then I get that runtime error and it gives the option to debug. Can anyone advise what's happening and how to fix it?
VBA Code:
Sub DailyReportFormatting()
'
' DailyReportFormatting Macro
'
' Keyboard Shortcut: Ctrl+w
'
With ActiveWindow
.SplitColumn = 0
.SplitRow = 1
End With
ActiveWindow.FreezePanes = True
Selection.AutoFilter
ActiveCell.Columns("A:A").EntireColumn.Select
Selection.ColumnWidth = 10.5
ActiveCell.Offset(0, 1).Columns("A:A").EntireColumn.Select
Selection.ColumnWidth = 8.5
ActiveCell.Offset(0, 1).Columns("A:A").EntireColumn.Select
Selection.ColumnWidth = 9.5
ActiveCell.Offset(0, 1).Columns("A:A").EntireColumn.Select
Selection.ColumnWidth = 15
ActiveCell.Offset(0, -2).Columns("A:A").EntireColumn.Select
Selection.NumberFormat = "#,##0.00_);[Red](#,##0.00)"
ActiveCell.Offset(4, 0).Range("A1").Select
ActiveWorkbook.Worksheets("Manual").AutoFilter.Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Manual").AutoFilter.Sort.SortFields.Add Key:= _
ActiveCell.Offset(-1, 0).Range("A1:A45"), SortOn:=xlSortOnValues, Order:= _
xlAscending, DataOption:=xlSortTextAsNumbers
With ActiveWorkbook.Worksheets("Manual").AutoFilter.Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
ActiveCell.Offset(-1, -1).Range("A1").Select
Sheets("PosEFT").Select
ActiveCell.Offset(-3, -10).Range("A1").Select
With ActiveWindow
.SplitColumn = 0
.SplitRow = 1
End With
ActiveWindow.FreezePanes = True
Selection.AutoFilter
ActiveCell.Columns("A:A").EntireColumn.Select
Selection.ColumnWidth = 10.5
ActiveCell.Offset(0, 1).Columns("A:A").EntireColumn.Select
Selection.ColumnWidth = 9
ActiveCell.Offset(0, 1).Columns("A:A").EntireColumn.Select
Selection.ColumnWidth = 12.5
ActiveCell.Offset(0, -1).Columns("A:A").EntireColumn.Select
Selection.NumberFormat = "#,##0.00_);[Red](#,##0.00)"
ActiveCell.Offset(4, 0).Range("A1").Select
ActiveWorkbook.Worksheets("PosEFT").AutoFilter.Sort.SortFields.Clear
ActiveWorkbook.Worksheets("PosEFT").AutoFilter.Sort.SortFields.Add Key:= _
ActiveCell.Offset(-1, 0).Range("A1:A366"), SortOn:=xlSortOnValues, Order:= _
xlAscending, DataOption:=xlSortTextAsNumbers
With ActiveWorkbook.Worksheets("PosEFT").AutoFilter.Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
ActiveCell.Offset(2, 3).Range("A1").Select
ActiveCell.FormulaR1C1 = "POS/EFT"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "POS/EFT QPC"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "POS/EFT VAN"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "Total"
ActiveCell.Offset(0, 1).Range("A1").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-3]C:R[-1]C)"
ActiveCell.Columns("A:A").EntireColumn.Select
Selection.NumberFormat = "#,##0.00_);[Red](#,##0.00)"
ActiveCell.Offset(0, -1).Columns("A:A").EntireColumn.Select
Selection.ColumnWidth = 12.5
ActiveCell.Offset(3, 1).Range("A1").Select
ActiveCell.FormulaR1C1 = "=SUMIF(C[-3],RC[-1],C[-4])"
ActiveCell.Offset(1, 0).Range("A1").Select
Selection.FillDown
ActiveCell.Offset(1, 0).Range("A1").Select
Selection.FillDown
ActiveCell.Offset(-5, -4).Range("A1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-366]C:R[-1]C)"
ActiveCell.Offset(0, -1).Range("A1").Select
ActiveCell.FormulaR1C1 = "Total"
ActiveCell.Range("A1:B1").Select
Selection.Font.Bold = True
ActiveCell.Offset(0, 2).Range("A1").Select
End Sub