Share via

Syntax Errors in Simple Excel Macro

Anonymous
2018-05-13T12:57:11+00:00

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

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

1 answer

Sort by: Most helpful
  1. DaveM121 891K Reputation points Independent Advisor
    2018-05-13T13:10:30+00:00

    Hi Pelo,

    Your son's macro is missing the code - With Selection.Font - which your macro does have, I think this is causing the error since the macro would not know which cell to start in and that would also cause the relative reference to fail . . .

    Was this answer helpful?

    0 comments No comments