Adding DataBar with VBA, minimum and maximum to automatic

Jaymond Flurrie

Well-known Member
Joined
Sep 22, 2008
Messages
919
Office Version
  1. 365
Platform
  1. Windows
First time trying Conditional Formatting with VBA.

I need a DataBar that is similar to manually adding one and in the Edit Formatting Rule dialog "Format all cells based on their values" in the "Edit Rule Description" has in the "Minimum" and "Maximum" as type "Automatic".

I know this all the way to adding the DataBar with Lowest Value and Highest Value in the Type.

Like:
VBA Code:
Private Sub cf()

    Dim target As Range
    Set target = Range("C3:S3")
    
    target.FormatConditions.Delete
    Dim db As Databar
    Set db = target.FormatConditions.AddDatabar
'    With db
'
'    End With
End Sub

My guess is that it is some property that needs to be set in the With-block, but what?
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Ok, got it (feel free to improve this):
VBA Code:
Private Sub adddatabar()

    Dim target As Range
    Set target = Range("C3:S3")
    
    target.FormatConditions.Delete
    target.FormatConditions.AddDatabar
    target.FormatConditions(target.FormatConditions.Count).ShowValue = True
    target.FormatConditions(target.FormatConditions.Count).SetFirstPriority
    
    With target.FormatConditions(1)
        .MinPoint.Modify newtype:=xlConditionValueAutomaticMin
        .MaxPoint.Modify newtype:=xlConditionValueAutomaticMax
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,001
Messages
6,122,648
Members
449,092
Latest member
peppernaut

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top