2016-03-03 167 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

相关问题