Excel_newbie2020
New Member
- Joined
- Dec 26, 2019
- Messages
- 2
- Office Version
- 2010
- Platform
- Windows
As a total newbie to Macros, I thought I could attempt something brave. Much of it worked, but when I tried to apply it to an arbitrary selection of highlighted cells (rows x columns), it failed. Hence the plead for from you pundits out there.
The requirements are to replace all numbers between the range of 1 and 9 in any set of highlighted cells where the font color is RED only to 1. The process is to first select a highlighted range of cells and then run the Macro for that range, such that only the RED numbers magically change to 1. This is what I tried, but if does not work on the highlighted cells. Wonder what's missing?
Thanks for your assistance in helping me out.
Sub Red()
Dim r As Range
Set r = Selection
For Each r In Selection
v = r.Value
If v <> "" And IsNumeric(v) Then
If v >= 1 And v <= 9 And Selection.Font.Color = vbRed Then
r.ClearContents
r.Value = "1"
End If
End If
Next r
End Sub
The requirements are to replace all numbers between the range of 1 and 9 in any set of highlighted cells where the font color is RED only to 1. The process is to first select a highlighted range of cells and then run the Macro for that range, such that only the RED numbers magically change to 1. This is what I tried, but if does not work on the highlighted cells. Wonder what's missing?
Thanks for your assistance in helping me out.
Sub Red()
Dim r As Range
Set r = Selection
For Each r In Selection
v = r.Value
If v <> "" And IsNumeric(v) Then
If v >= 1 And v <= 9 And Selection.Font.Color = vbRed Then
r.ClearContents
r.Value = "1"
End If
End If
Next r
End Sub