Modifying the color of a data bar with conditional formatting through VBA

Moonbeam111

Board Regular
Joined
Sep 24, 2018
Messages
101
Office Version
  1. 365
  2. 2010
How do I change the color of a data bar with conditional formatting through VBA? I only would like to adjust just the color. No other properties need to be created or set.

This is what my Conditional Formatting is in Range ("E2:G2") (its a merged cell)

I know this has probably got to be a pretty easy solution but the answer is eluding me.

.
pic.png
 
Something like this?

VBA Code:
Option Explicit

Sub ChangeDataBarColor()

    Dim rng As Range
    Dim ws As Worksheet
    Dim dataBar As dataBar
  
    Set ws = ActiveSheet
    Set rng = ws.Range("E2:G2")
      
    For Each dataBar In rng.FormatConditions
            dataBar.BarColor.Color = 'insert color here
    Next dataBar
  
    Set ws = Nothing
    Set rng = Nothing

End Sub
 
Upvote 0
Yes. That is what I had in mind. However, I only have 1 data bar in my workbook.

VBA Code:
    For Each dataBar In rng.FormatConditions
            dataBar.BarColor.Color = 'insert color here
    Next dataBar

How would i modify the code to apply to the one data bar I have in Range("E2:G2")?
 
Upvote 0
Try this:

VBA Code:
Option Explicit

Sub ChangeDataBarColor()

    Dim rng As Range
    Dim ws As Worksheet
    Dim dataBar As dataBar
 
    Set ws = ActiveSheet
    Set rng = ws.Range("E2:G2")
     
    Set dataBar = rng.FormatConditions(1)
 
    dataBar.BarColor.Color = 'insert color here

End Sub
 
Upvote 0
Solution

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