DonStewart
New Member
- Joined
- May 15, 2018
- Messages
- 3
I tested this script and it walks through all 27000 cells (D3 - AZ500), changing each that is not blank to a red background:
Dim MyVar As String
Dim i As Integer
Range("D3").Select
For i = 1 To 27000
If ActiveCell.Value = "" Then
ActiveCell.Offset(1, 0).Select
Range("D" & (ActiveCell.Row)).Select
Else:
With Selection
.Interior.ColorIndex = 3
ActiveCell.Offset(0, 1).Select
End With
End If
Next
But when I add the code for a "MyVar" variable and change color only when it matches. ONLY the matches in column D are marked. Can anyone see why these extra lines are preventing it from searching, matching, and marking the variable matches in columns E through the first blank cell in that row?
Dim MyVar As String
Dim i As Integer
Range("D3").Select
MyVar = ActiveCell.Value
If ActiveCell.Value = "" Then
ActiveCell.Offset(1, 0).Select
Range("D" & (ActiveCell.Row)).Select
Else:
With Selection
If ActiveCell.Value <> MyVar Then
ActiveCell.Offset(0, 1).Select
Else
.Interior.ColorIndex = 3
ActiveCell.Offset(0, 1).Select
End If
End With
End If
Next
Dim MyVar As String
Dim i As Integer
Range("D3").Select
For i = 1 To 27000
If ActiveCell.Value = "" Then
ActiveCell.Offset(1, 0).Select
Range("D" & (ActiveCell.Row)).Select
Else:
With Selection
.Interior.ColorIndex = 3
ActiveCell.Offset(0, 1).Select
End With
End If
Next
But when I add the code for a "MyVar" variable and change color only when it matches. ONLY the matches in column D are marked. Can anyone see why these extra lines are preventing it from searching, matching, and marking the variable matches in columns E through the first blank cell in that row?
Dim MyVar As String
Dim i As Integer
Range("D3").Select
MyVar = ActiveCell.Value
If ActiveCell.Value = "" Then
ActiveCell.Offset(1, 0).Select
Range("D" & (ActiveCell.Row)).Select
Else:
With Selection
If ActiveCell.Value <> MyVar Then
ActiveCell.Offset(0, 1).Select
Else
.Interior.ColorIndex = 3
ActiveCell.Offset(0, 1).Select
End If
End With
End If
Next