My son is beginning to learn to work with macros in Excel and has run into a puzzling problem. He has a very simple macro to reformat the font in a cell and delete a row (relative reference) and a column (absolute reference).
When he records and attempts to run the macro on his computer he gets syntax errors. When I record the exact same steps on my computer it works fine and the generated code is significantly different. We are both using Excel 2016 and Windows 10. Below is
the code for both the non-working and working macros.
I'm stumped where to look for what might be causing the code to be different and non-functional. Any help would be appreciated.
Code with Syntax Errors
Sub FornatCells()
'
' FornatCells Macro
'
'
Application. = FALSE
With .Color
.MeasureName = "Arial"
.ErrorString = 11
.HasAutoFormat = False
.MergeLabels = False
.PageFieldOrder = False
.NullString = False
.ActiveSheet = False
.PreserveFormatting = xlUnderlineStyleNone
.Order = xlThemeColorLight1
.Symbol = 0
.PrintDrillIndicators = xlThemeFontNone
End With
With .Color
.MeasureName = "Arial"
.ErrorString = 14
.HasAutoFormat = False
.MergeLabels = False
.PageFieldOrder = False
.NullString = False
.ActiveSheet = False
.PreserveFormatting = xlUnderlineStyleNone
.Order = xlThemeColorLight1
.Symbol = 0
.PrintDrillIndicators = xlThemeFontNone
End With
.Color.ShowDrillIndicators = True
With
. = xlCenter
. = xlBottom
. = FALSE
. = 0
. = FALSE
. = 0
. = FALSE
. = xlContext
. = FALSE
End With
ActiveCell.Offset(1, 0).Rows("1:1").EntireRow.ErrorString
. := xlUp
Columns("A:A").ErrorString
. := xlToLeft
End Sub
Code Without Errors
Sub Macro1Good()
'
' Macro1Good Macro
'
'
With Selection.Font
.Name = "Arial"
.Size = 11
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ThemeColor = xlThemeColorLight1
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
With Selection.Font
.Name = "Arial"
.Size = 14
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ThemeColor = xlThemeColorLight1
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
Selection.Font.Bold = True
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
ActiveCell.Offset(1, 0).Rows("1:1").EntireRow.Select
Selection.Delete Shift:=xlUp
Columns("A:A").Select
Selection.Delete Shift:=xlToLeft
End Sub