mattyg1406
New Member
- Joined
- Feb 6, 2015
- Messages
- 10
I currently have a piece of code which applies some simple colour conditional formatting on blank cells on a set column on my workbook
:
I would like to make this code more dynamic, and use a named range reference for column G, as it is quite likely that additional columns may get added to the workbook in the future, and I don't want to have to keep amending my code.
I plan to use a named range for the "G9:G125" address, so the conditional formatting would need to find the first blank cell in the named range and apply formatting up to the end of the named range.
Does anyone have any suggestions to help me with this please?
:
Code:
wsEmployeeData.Range("G" & LastEmployeeDataRow + 1 & ":G125").FormatConditions.Add Type:=xlExpression, Formula1:= _
"=AND('" & wsEmployeeData.Name & "'!$C" & LastEmployeeDataRow + 1 & "<>"""",'" & wsEmployeeData.Name & "'!$G" & LastEmployeeDataRow + 1 & "<>"""")"
wsEmployeeData.Range("G" & LastEmployeeDataRow + 1 & ":G125").FormatConditions(wsEmployeeData.Range("G" & LastEmployeeDataRow + 1 & ":G125") _
.FormatConditions.Count).SetFirstPriority
With wsEmployeeData.Range("G" & LastEmployeeDataRow + 1 & ":G125").FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = RGB(0, 255, 255) ' Blue ( Optional )
.TintAndShade = 0
End With
wsEmployeeData.Range("G" & LastEmployeeDataRow + 1 & ":G125").FormatConditions(1).StopIfTrue = False
I would like to make this code more dynamic, and use a named range reference for column G, as it is quite likely that additional columns may get added to the workbook in the future, and I don't want to have to keep amending my code.
I plan to use a named range for the "G9:G125" address, so the conditional formatting would need to find the first blank cell in the named range and apply formatting up to the end of the named range.
Does anyone have any suggestions to help me with this please?