Hi there, I'm trying to create a macro to auto recolor cells based on some criteria:
I've made the following code to all execute on a single sub, which is where the issue arises I think. Is there a way to combine this as a single shortcut?
Apologies for any messy code - first time learning this, and couldn't find an easy way to code up a "Find All".
- Blue for numbers
- Cyan for direct links from other worksheets
- Magenta for links to other workbooks
I've made the following code to all execute on a single sub, which is where the issue arises I think. Is there a way to combine this as a single shortcut?
Apologies for any messy code - first time learning this, and couldn't find an easy way to code up a "Find All".
Code:
Sub AutoRecolor()
' Change hardcode numbers
Selection.SpecialCells(xlCellTypeConstants, 1).Select
With Selection.Font
.Color = Blue
End With
' Change sheets
Dim fnd As String, FirstFound As String
Dim FoundCell As Range, rng As Range
Dim myRange As Range, LastCell As Range
'search term (other sheets)
fnd = "!"
Set myRange = ActiveSheet.UsedRange
Set LastCell = myRange.Cells(myRange.Cells.Count)
Set FoundCell = myRange.Find(what:=fnd, after:=LastCell)
Set rng = FoundCell
'Loop until cycled through all unique finds
Do Until FoundCell Is Nothing
'Find next cell with fnd value
Set FoundCell = myRange.FindNext(after:=FoundCell)
'Add found cell to rng range variable
Set rng = Union(rng, FoundCell)
'Test to see if cycled through to first found cell
If FoundCell.Address = FirstFound Then Exit Do
Loop
'Change font to cyan
rng.Font.Color = Cyan
' NOW FOR OTHER WORKBOOKS
Dim fnd As String, FirstFound As String
Dim FoundCell As Range, rng As Range
Dim myRange As Range, LastCell As Range
'search term (other workbooks)
fnd = ".xl"
Set myRange = ActiveSheet.UsedRange
Set LastCell = myRange.Cells(myRange.Cells.Count)
Set FoundCell = myRange.Find(what:=fnd, after:=LastCell)
Set rng = FoundCell
'Loop until cycled through all unique finds
Do Until FoundCell Is Nothing
'Find next cell with fnd value
Set FoundCell = myRange.FindNext(after:=FoundCell)
'Add found cell to rng range variable
Set rng = Union(rng, FoundCell)
'Test to see if cycled through to first found cell
If FoundCell.Address = FirstFound Then Exit Do
Loop
'Change font to magenta
rng.Font.Color = Magenta
End Sub