复制数据栏格式

时间:2016-07-18 12:33:38

标签: excel formatting

我有各种不同值的行需要相互比较:

Col1    Col2    Col3    Col4
1       84      90      75
1       90      65      89

我希望每行都有数据栏格式,以便数据栏格式化只考虑特定行中的值。例如,在第1行中,Col3的数据栏将满,而其他数据栏将小于满,因为Col3是最高值,而其他柱应该反映与此相比的单元格值。

由于行数太多,我无法手动每行排行。

1 个答案:

答案 0 :(得分:0)

这是一个适合您的VBA解决方案。您必须调整以下语句:

设置myRange = Columns(" B:D")< ---您希望宏在哪些列上运行?

对于i = 2到3< --- ...以及在哪些行上?

Sub FormatRows()

Dim myRange As Range
Set myRange = Columns("B:D")

For i = 2 To 3
Rows(i).Columns("B:D").Select
    Selection.FormatConditions.AddDatabar
    Selection.FormatConditions(Selection.FormatConditions.Count).ShowValue = True
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1)
        .MinPoint.Modify newtype:=xlConditionValueAutomaticMin
        .MaxPoint.Modify newtype:=xlConditionValueAutomaticMax
    End With
    With Selection.FormatConditions(1).BarColor
        .Color = 13012579
        .TintAndShade = 0
    End With
    Selection.FormatConditions(1).BarFillType = xlDataBarFillSolid
    Selection.FormatConditions(1).Direction = xlContext
    Selection.FormatConditions(1).NegativeBarFormat.ColorType = xlDataBarColor
    Selection.FormatConditions(1).BarBorder.Type = xlDataBarBorderNone
    Selection.FormatConditions(1).AxisPosition = xlDataBarAxisAutomatic
    With Selection.FormatConditions(1).AxisColor
        .Color = 0
        .TintAndShade = 0
    End With
    With Selection.FormatConditions(1).NegativeBarFormat.Color
        .Color = 255
        .TintAndShade = 0
    End With
    Next i
End Sub