i'm new to macros; i recorded this one that doesn't work. please help!

bigdan

Well-known Member
Joined
Oct 5, 2009
Messages
840
Office Version
  1. 2013
Platform
  1. Windows
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?

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
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Which is the error and wich line generate it (the line highlighted after you enter the debug process)?

Has the macro been recorded on the same pc that you are now using it?

Bye
 
Upvote 0
It would also be easier to help, if you explained what you are trying to do. Deciphering code that includes lots of "Activecell" is almost impossible as we have no idea what the active cell was when you ran the code.

The second line here
VBA Code:
    Sheets("PosEFT").Select
    ActiveCell.Offset(-3, -10).Range("A1").Select
will give an error if the activecell is in rows 1,2 or 3, or the column is A:J
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,732
Members
448,987
Latest member
marion_davis

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