Conditional Formatting Beginner

Data Bars for Quick Comparison

Add data bars to cells for instant visual comparison of values

14 views

Perfect For:

  • Sales comparison
  • Progress tracking
  • Budget analysis
VBA Code
Sub AddDataBars()
    Dim dataRange As Range
    Dim dataBar As Databar

    ' Select the data range
    Set dataRange = Application.InputBox("Select range for data bars:", Type:=8)

    If dataRange Is Nothing Then Exit Sub

    ' Clear existing conditional formatting
    dataRange.FormatConditions.Delete

    ' Add data bars
    Set dataBar = dataRange.FormatConditions.AddDatabar

    ' Configure data bar appearance
    With dataBar
        .MinPoint.Modify newtype:=xlConditionValueAutomaticMin
        .MaxPoint.Modify newtype:=xlConditionValueAutomaticMax
        .BarColor.Color = RGB(91, 155, 213)  ' Blue bars
        .ShowValue = True  ' Show values alongside bars
        .BarFillType = xlDataBarFillSolid
    End With

    MsgBox "Data bars added successfully!"
End Sub

Related Topics

data bars comparison visualization progress

Need Custom VBA Solutions?

Our AI-powered VBA generator can create custom code tailored to your specific requirements in seconds.

Generate Custom VBA Code

Related Templates

More VBA templates in the same category

Beginner

Highlight Duplicate Values

Automatically highlight duplicate values in a range with conditional formatting

View Template