As per standard excel the length of databar is equal to the value in the cell where the databar is displayed (subject to upper and lower limits specified in other cells).
Following macro allows me to create a Databar using min. and max range between cells A3 to A4, and the databar is displayed in cells A2 to A4.
Sub databars() Dim rg As Range Dim db As Databar Set rg = Range("A2", Range("A3").Range("A4")) Set db = rg.FormatConditions.AddDatabar With db .BarColor.Color = vbGreen .BarFillType = xlDataBarFillGradient End With End Sub
I was wondering whether it could be possible to modify the macro to display the databar in Cell A1, with the databar length corresponding to value in cell A2 and min/ max range being held in cells A3 to A4.
For example, if the Value in cell A2 is 300, and range in cells A3-A4 is 1-900, the length of databar being displayed in cell A1 should correspond to 300, even though the value in cell A1 is 600. (Perhaps the databar could read the cell value from a range in the macro itself and display the databar in the worksheet)
Also, the databars are currently being displayed in cell A2 to A4. I believe this is because I have not defined rg As Range properly. Can someone please help to let the databar appear only in cell A2.
Sample file attached.
Note: This is a duplicate post from another forum. No reply received there, so request posted on this forum