Last active
August 29, 2015 14:05
-
-
Save worldofchris/c1652352f55619c0420f to your computer and use it in GitHub Desktop.
Format Excel CFD
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub ColorMatchingCells(toMatch, color, topLeft, bottomRight) | |
' | |
' Colour in the different states in the Cumulative Flow Diagram | |
' | |
Range(topLeft, bottomRight).Select | |
'Cells.FormatConditions.Delete | |
Selection.FormatConditions.Add Type:=xlTextString, _ | |
String:=toMatch, _ | |
TextOperator:=xlContains | |
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority | |
With Selection.FormatConditions(1).Interior | |
.Pattern = xlSolid | |
.PatternColor = color | |
.ColorIndex = color | |
End With | |
Selection.FormatConditions(1).Font.ColorIndex = 27 | |
Selection.FormatConditions(1).StopIfTrue = False | |
End Sub | |
Sub LoopOverRange(colorLookupRange, topLeft, bottomRight) | |
NumRows = Range(colorLookupRange, Range(colorLookupRange).End(xlDown)).Rows.Count | |
For x = 0 To NumRows - 1 | |
Debug.Print (toMatch) | |
toMatch = Range(colorLookupRange).Offset(x).Value | |
color = Range(colorLookupRange).Offset(x, 1).Value | |
Call ColorMatchingCells(toMatch, color, topLeft, bottomRight) | |
Next | |
End Sub | |
Sub formatCFD() | |
Call LoopOverRange("A51", "B2", "CJ49") | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment