none
Problem with record macro in Excel 2010? RRS feed

  • Question

  • i red many website that talking about recording macro in Excel 2010, and i following it, but there is an some issue appearing me, i recorded macro in excel 2010 for doing auto some formatting in tables existing, an error message appears me when i select another table in the sheet, runtime error 1004, here is my record macro,

    Sub Mustafa()
    '
    ' Mustafa Macro
    '
    
    '
        ActiveSheet.ListObjects.Add(xlSrcRange, Range("$A$8:$C$12"), , xlYes).Name = _
            "Table1"
        Range("Table1[#All]").Select
        ActiveSheet.ListObjects("Table1").TableStyle = "TableStyleMedium5"
        Selection.Font.Bold = True
        Selection.Borders(xlDiagonalDown).LineStyle = xlNone
        Selection.Borders(xlDiagonalUp).LineStyle = xlNone
        With Selection.Borders(xlEdgeLeft)
            .LineStyle = xlContinuous
            .ColorIndex = 0
            .TintAndShade = 0
            .Weight = xlThin
        End With
        With Selection.Borders(xlEdgeTop)
            .LineStyle = xlContinuous
            .ColorIndex = 0
            .TintAndShade = 0
            .Weight = xlThin
        End With
        With Selection.Borders(xlEdgeBottom)
            .LineStyle = xlContinuous
            .ColorIndex = 0
            .TintAndShade = 0
            .Weight = xlThin
        End With
        With Selection.Borders(xlEdgeRight)
            .LineStyle = xlContinuous
            .ColorIndex = 0
            .TintAndShade = 0
            .Weight = xlThin
        End With
        With Selection.Borders(xlInsideVertical)
            .LineStyle = xlContinuous
            .ColorIndex = 0
            .TintAndShade = 0
            .Weight = xlThin
        End With
        With Selection.Borders(xlInsideHorizontal)
            .LineStyle = xlContinuous
            .ColorIndex = 0
            .TintAndShade = 0
            .Weight = xlThin
        End With
        With Selection
            .HorizontalAlignment = xlGeneral
            .VerticalAlignment = xlBottom
            .Orientation = 0
            .AddIndent = False
            .IndentLevel = 0
            .ShrinkToFit = False
            .ReadingOrder = xlContext
            .MergeCells = False
        End With
        With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlBottom
            .Orientation = 0
            .AddIndent = False
            .IndentLevel = 0
            .ShrinkToFit = False
            .ReadingOrder = xlContext
            .MergeCells = False
        End With
        With Selection.Font
            .Name = "Calibri"
            .Size = 10
            .Strikethrough = False
            .Superscript = False
            .Subscript = False
            .OutlineFont = False
            .Shadow = False
            .Underline = xlUnderlineStyleNone
            .ColorIndex = 1
            .TintAndShade = 0
            .ThemeFont = xlThemeFontNone
        End With
        With Selection.Font
            .Name = "Arial"
            .Size = 10
            .Strikethrough = False
            .Superscript = False
            .Subscript = False
            .OutlineFont = False
            .Shadow = False
            .Underline = xlUnderlineStyleNone
            .ColorIndex = 1
            .TintAndShade = 0
            .ThemeFont = xlThemeFontMinor
        End With
        Range("Table1[[#Headers],[Parcel_Main_Landuse_A]]").Select
        ActiveCell.FormulaR1C1 = "Parcel_Main_Landuse_A"
    End Sub


         

    • Edited by GIS Man Tuesday, July 2, 2013 12:42 PM
    Tuesday, July 2, 2013 12:40 PM

All replies

  • here is result of the debug code,

    the error in this line

    ActiveSheet.ListObjects.Add(xlSrcRange, Range("$A$8:$C$12"), , xlYes).Name = _
            "Table1"

    Tuesday, July 2, 2013 12:56 PM