+ Reply to Thread
Results 1 to 3 of 3

Create Table Style Macro Not Producing Expected Results

Hybrid View

  1. #1
    Registered User
    Join Date
    08-16-2007
    Posts
    50

    Create Table Style Macro Not Producing Expected Results

    Hello All,
    I am trying to create a macro that will create a table style with a thin black line around the table and header cells, dashed grey lines separating cells in the body, and header text bold. I recorded a macro creating the table style format I want, then renamed the style I created and ran the recorded macro. The table style created by the recorded macro does not look the same as the style I created when recording it. The style produced by the recorded macro does not have any of the borders I created, but I can't tell why when I look at the code. An example spreadsheet with the table style I created and the one produced by the recorded macro is attached, and the recorded code is below. I would be greatly appreciated if someone would explain why the macro isn't producing what I expected and/or point me the right direction for how to get a macro to produce what I'm looking for.
    Thanks

    TableStyleExampleWorkbook.xlsm

    Sub CreateTableStyleTest()
    '
    ' CreateTableStyleTest Macro
    '
    
    '
        ActiveWorkbook.TableStyles.Add ("NewTableStyle1")
        With ActiveWorkbook.TableStyles("NewTableStyle1")
            .ShowAsAvailablePivotTableStyle = False
            .ShowAsAvailableTableStyle = True
            .ShowAsAvailableSlicerStyle = False
        End With
        With ActiveWorkbook.TableStyles("NewTableStyle1").TableStyleElements( _
            xlWholeTable).Borders(xlEdgeTop)
            .ColorIndex = xlAutomatic
            .TintAndShade = 0
            .Weight = xlThin
            .LineStyle = xlNone
        End With
        With ActiveWorkbook.TableStyles("NewTableStyle1").TableStyleElements( _
            xlWholeTable).Borders(xlEdgeBottom)
            .ColorIndex = xlAutomatic
            .TintAndShade = 0
            .Weight = xlThin
            .LineStyle = xlNone
        End With
        With ActiveWorkbook.TableStyles("NewTableStyle1").TableStyleElements( _
            xlWholeTable).Borders(xlEdgeLeft)
            .ColorIndex = xlAutomatic
            .TintAndShade = 0
            .Weight = xlThin
            .LineStyle = xlNone
        End With
        With ActiveWorkbook.TableStyles("NewTableStyle1").TableStyleElements( _
            xlWholeTable).Borders(xlEdgeRight)
            .ColorIndex = xlAutomatic
            .TintAndShade = 0
            .Weight = xlThin
            .LineStyle = xlNone
        End With
        With ActiveWorkbook.TableStyles("NewTableStyle1").TableStyleElements( _
            xlWholeTable).Borders(xlInsideVertical)
            .ThemeColor = xlThemeColorDark1
            .TintAndShade = -0.349986266670736
            .Weight = xlThin
            .LineStyle = xlContinuous
        End With
        With ActiveWorkbook.TableStyles("NewTableStyle1").TableStyleElements( _
            xlWholeTable).Borders(xlInsideHorizontal)
            .ThemeColor = xlThemeColorDark1
            .TintAndShade = -0.349986266670736
            .Weight = xlThin
            .LineStyle = xlContinuous
        End With
        ActiveWorkbook.TableStyles("NewTableStyle1").TableStyleElements(xlHeaderRow). _
            Font.FontStyle = "Bold"
        With ActiveWorkbook.TableStyles("NewTableStyle1").TableStyleElements( _
            xlHeaderRow).Borders(xlEdgeTop)
            .ColorIndex = xlAutomatic
            .TintAndShade = 0
            .Weight = xlThin
            .LineStyle = xlNone
        End With
        With ActiveWorkbook.TableStyles("NewTableStyle1").TableStyleElements( _
            xlHeaderRow).Borders(xlEdgeBottom)
            .ColorIndex = xlAutomatic
            .TintAndShade = 0
            .Weight = xlThin
            .LineStyle = xlNone
        End With
        With ActiveWorkbook.TableStyles("NewTableStyle1").TableStyleElements( _
            xlHeaderRow).Borders(xlEdgeLeft)
            .ColorIndex = xlAutomatic
            .TintAndShade = 0
            .Weight = xlThin
            .LineStyle = xlNone
        End With
        With ActiveWorkbook.TableStyles("NewTableStyle1").TableStyleElements( _
            xlHeaderRow).Borders(xlEdgeRight)
            .ColorIndex = xlAutomatic
            .TintAndShade = 0
            .Weight = xlThin
            .LineStyle = xlNone
        End With
        With ActiveWorkbook.TableStyles("NewTableStyle1").TableStyleElements( _
            xlHeaderRow).Borders(xlInsideVertical)
            .ColorIndex = xlAutomatic
            .TintAndShade = 0
            .Weight = xlThin
            .LineStyle = xlNone
        End With
        With ActiveWorkbook.TableStyles("NewTableStyle1").TableStyleElements( _
            xlHeaderRow).Borders(xlInsideHorizontal)
            .ColorIndex = xlAutomatic
            .TintAndShade = 0
            .Weight = xlThin
            .LineStyle = xlNone
        End With
    End Sub

  2. #2
    Registered User
    Join Date
    06-12-2015
    Location
    WA
    MS-Off Ver
    10
    Posts
    33

    Re: Create Table Style Macro Not Producing Expected Results

    Add this into your macro.
        Range("Table2[#All]").Select ' make sure you idenfity the range you're trying to select.
        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
        Selection.Borders(xlInsideVertical).LineStyle = xlNone
        Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
        Range("A1").Select

  3. #3
    Registered User
    Join Date
    08-16-2007
    Posts
    50

    Re: Create Table Style Macro Not Producing Expected Results

    Thanks for your help. I believe the code gave changes the boarders of the range of the table, but I'm looking to create a table style that can be applied to any table. However, your code gave me a hint and I figured it out. I had to change the line style to .LineStyle = xlContinuous for outside boarders and .LineStyle = xlDash for inside boarders. Thanks again for your help!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Expected table is not in the expected format - ADODB Connection to Read Only Excel file
    By Roshan10043 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-05-2018, 10:54 AM
  2. if statement not producing value expected
    By Sc0tt1e in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-21-2015, 02:50 PM
  3. Replies: 2
    Last Post: 08-24-2014, 04:56 AM
  4. Macros: Data cleaning macros not producing expected outputes.
    By bertlogdi1 in forum Excel Programming / VBA / Macros
    Replies: 31
    Last Post: 06-17-2011, 06:52 AM
  5. Macro is not generating expected results.
    By Foxcan in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-10-2009, 04:16 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1