I cannot understand why excel stopped recognizing the headers of listed objects; specifically this line Range("Offer_Table[[#Headers], [LOC]").Select
I would like to change the format of specific header and I first was able to do it using the following code.
Range("Offer_Table[[#Headers], [LOC]").Select
With Selection.Font
.Name = "Calibri"
.FontStyle = "Bold"
.Size = 11
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ThemeColor = xlThemeColorAccent2
.TintAndShade = -0.249977111
.ThemeFont = xlThemeFontMinor
End With
With Selection.Interior
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent4
.TintAndShade = 0.799981688894314
.PatternTintAndShade = 0
End With
however, the code stopped working once I closed all active sheets to run a first complete test on a new sheet. I do not understand why but headers now are no longer recognized by Excel. Either if I create a new LO from VBA or I do it manually setting a new table.
Below is the sample code
'Referring to the Table
Dim Offer_table As ListObject
CntCol = Range(Cells(1, 1), Cells(1, 1).End(xlToRight)).Count
CntRow = Range(Cells(1, 2), Cells(1, 2).End(xlDown)).Count
MsgBox CntCol
MsgBox CntRow
Set Offer_table = ActiveSheet.ListObjects.Add(xlSrcRange, Range(Cells(1, 1), Cells(CntRow, CntCol)), , xlYes)
Offer_table.Name = "Offer_Table"
Offer_table.TableStyle = "TableStyleLight2"
'Highlight headers
Range("Offer_Table[[#Headers], [Order Creation]").Select
With Selection.Font
.Name = "Calibri"
.FontStyle = "Bold"
.Size = 11
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ThemeColor = xlThemeColorAccent2
.TintAndShade = -0.249977111
.ThemeFont = xlThemeFontMinor
End With
With Selection.Interior
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent4
.TintAndShade = 0.799981688894314
.PatternTintAndShade = 0
End With
Range("Offer_Table[[#Headers],[SEGMENT]").Select
With Selection.Font
.Name = "Calibri"
.FontStyle = "Bold"
.Size = 11
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ThemeColor = xlThemeColorAccent2
.TintAndShade = -0.249977111
.ThemeFont = xlThemeFontMinor
End With
With Selection.Interior
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent4
.TintAndShade = 0.799981688894314
.PatternTintAndShade = 0
End With