2016-03-03 206 views
0

我有麻煩圖表中格式化列以匹配特定的字體,顏色,取向等Excel VBA中列在圖表 - 格式字體,顏色,取向等

該代碼,而集中在柱A:它適用於工作表中的每個單元格。我只希望它影響列A:

Sub PGMNumber() 
' 
' PGMNumber Macro 
' 

' 
    Range("A:A").Select 
    With Selection.Font 
     .Name = "Arial" 
     .Size = 10 
     .Strikethrough = False 
     .Superscript = False 
     .Subscript = False 
     .OutlineFont = False 
     .Shadow = False 
     .Underline = xlUnderlineStyleNone 
     .Color = -16776961 
     .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 
     .Color = -16776961 
     .TintAndShade = 0 
     .ThemeFont = xlThemeFontNone 
    End With 
    Selection.Font.Bold = False 
    Selection.Font.Bold = True 
    With Selection.Font 
     .Color = -10477568 
     .TintAndShade = 0 
    End With 
    With Selection 
     .HorizontalAlignment = xlLeft 
     .VerticalAlignment = xlBottom 
     .WrapText = False 
     .Orientation = 0 
     .AddIndent = False 
     .IndentLevel = 0 
     .ShrinkToFit = False 
     .ReadingOrder = xlContext 
     .MergeCells = False 
    End With 
    Columns("A:A").ColumnWidth = 9.43 
End Sub 

這是通過記錄我的步驟完成的。我需要的只是FontName,Color,Bold,Size和Alignment。刪除的內容,我不需要休息的代碼:(

人可以幫我簡化代碼,以便它只會影響A列?

此外,如何添加的選項包括其他列,例如B,C,d等

最後,我可以有宏開始從A6格式化向下,向下B6,C6向下,等?這樣的圖的頭保持不變。

謝謝!

回答

0

這將從行格式列A 6倒。那裏有兩種字體顏色,我刪除了第一種。要改變這種代碼的列中,更改「A」 S的範圍()你要定位的列,例如.Range("B6:B" & .Cells(.Rows.Count, "B")

Sub PGMNumber() 
    ' PGMNumber Macro 
     Dim FormatRange As Range 
     With ThisWorkbook.ActiveSheet 
      Set FormatRange = .Range("A6:A" & .Cells(.Rows.Count, "A").End(xlUp).Row) 
     End With 
     With FormatRange 
      With .Font 
       .Name = "Arial" 
       .Size = 10 
       .Bold = True 
       .Color = -10477568 
      End With 
      .HorizontalAlignment = xlLeft 
      .VerticalAlignment = xlBottom 
     End With 
    End Sub 
+0

這完美地工作!現在如果我想讓這個宏的格式一次多於一列,該怎麼辦?我在哪裏輸入第二欄的代碼?具體是B列......謝謝泰勒! @Taylor – BMRobin

+0

如果列都彼此相鄰,在.Range第二個「A」改爲你所需要的最後一列,例如'.Range(「A6:d」&...' – Toast

+0

如果問題得以解決,請註明答案接受 – Toast

0

你可以使用這個宏,其中兩個單元範圍()是你的左上角單元格和範圍格式的右下角細胞。

Sub PGMNumber() 
    With Range(Cells(6, "A"), Cells(Rows.Count, "D")) 
     With .Font 
      .Name = "Arial" 
      .Size = 10 
      .Color = -16776961 
      .Bold = True 
     End With 
     .HorizontalAlignment = xlLeft 
     .VerticalAlignment = xlBottom 
    End With 
End Sub 
+0

這幫助了很多簡單扼要。! – BMRobin

相關問題