Share via

Debugging Excel VBA code

Anonymous
2020-06-27T11:53:49+00:00

Hi Folks,

New to macros in Excel. What is wrong?

Columns("H:H").Select

    Selection.Cut

    Columns("G:G").Select

    Selection.Insert Shift:=xlToRight

    Columns("J:P").Select

    Selection.Style = "Percent"

    Range("A1:P8").Select

    ActiveSheet.ListObjects.Add(xlSrcRange, Range("$A$1:$P$8"), , xlYes).Name = _

        "Table7"

    Range("Table7[#All]").Select

According to the debugger, my macro is stuck at the Range line.

Any help would be appreciated. 

Thank you.

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. Anonymous
    2020-06-27T15:30:34+00:00

    The code on it's own works fine (I've replicated it).

    The only problem occurs if you try to run it twice and Table7 already exists - but then the line above the range line bombs.

    Is there an existing table there and/or one called Table7?

    Hard coding a table name like this is not a good idea but it should be OK in a clean book..

    1 person found this answer helpful.
    0 comments No comments