TaskMaster
Board Regular
- Joined
- Oct 15, 2020
- Messages
- 75
- Office Version
- 365
- 2016
- Platform
- Windows
Hi all,
Hoping you could help me with my issue. I wanted to add databars to my spreadsheet however when doing manually I got the error cannot use relative references which would mean applying the same formula over and over again. A way around this I thought would be to use vba to apply this. This works for the first set of formatting but when using the others it seems to overwrite it even though the parameters are different could anyone provide a solution to this. I need this for 6 different people. I want the conditions of the data bar be a different colour for each person, where the persons name is in column F.
Hoping you could help me with my issue. I wanted to add databars to my spreadsheet however when doing manually I got the error cannot use relative references which would mean applying the same formula over and over again. A way around this I thought would be to use vba to apply this. This works for the first set of formatting but when using the others it seems to overwrite it even though the parameters are different could anyone provide a solution to this. I need this for 6 different people. I want the conditions of the data bar be a different colour for each person, where the persons name is in column F.
VBA Code:
Sub Data_Bar_James()
Dim r As Integer
Dim lr As Integer
lr = Cells(Rows.Count, "F").End(xlUp).Row
Application.ScreenUpdating = False
For r = 2 To lr
With Range("G" & r)
.FormatConditions.AddDatabar
With .FormatConditions(1)
.MinPoint.Modify newtype:=xlConditionValueFormula, newvalue:="=IF(Whiteboard!$F$" & r & "=""James"",0,"""")"
.MaxPoint.Modify newtype:=xlConditionValueFormula, newvalue:="=IF(Whiteboard!$F$" & r & "=""James"",1,"""")"
.ShowValue = True
.BarFillType = xlDataBarFillSolid
.BarColor.Color = 2222055
End With
End With
Next r
Application.ScreenUpdating = False
End Sub
Sub Data_Bar_Tim()
Dim r As Integer
Dim lr As Integer
lr = Cells(Rows.Count, "F").End(xlUp).Row
Application.ScreenUpdating = False
For r = 2 To lr
With Range("G" & r)
.FormatConditions.AddDatabar
With .FormatConditions(1)
.MinPoint.Modify newtype:=xlConditionValueFormula, newvalue:="=IF(Whiteboard!$F$" & r & "=""Tim"",0,"""")"
.MaxPoint.Modify newtype:=xlConditionValueFormula, newvalue:="=IF(Whiteboard!$F$" & r & "=""Tim"",1,"""")"
.ShowValue = True
.BarFillType = xlDataBarFillSolid
.BarColor.Color = 255
End With
End With
Next r
Application.ScreenUpdating = False
End Sub
Sub Data_Bar_Lisa()
Dim r As Integer
Dim lr As Integer
lr = Cells(Rows.Count, "F").End(xlUp).Row
Application.ScreenUpdating = False
For r = 2 To lr
With Range("G" & r)
.FormatConditions.AddDatabar
With .FormatConditions(1)
.MinPoint.Modify newtype:=xlConditionValueFormula, newvalue:="=IF(Whiteboard!$F$" & r & "=""Lisa"",0,"""")"
.MaxPoint.Modify newtype:=xlConditionValueFormula, newvalue:="=IF(Whiteboard!$F$" & r & "=""Lisa"",1,"""")"
.ShowValue = True
.BarFillType = xlDataBarFillSolid
.BarColor.Color = 15523812
End With
End With
Next r
Application.ScreenUpdating = False
End Sub