VBAProIWish
Well-known Member
- Joined
- Jul 6, 2009
- Messages
- 1,027
- Office Version
- 365
- Platform
- Windows
Hello All,
There are 2 Code snippets below. The first code snippet works fine, but the second code snippet with the additional code highlighted in red does NOT. Does anyone know how to fix this? Thanks
FIRST CODE SNIPPET
SECOND CODE SNIPPET
There are 2 Code snippets below. The first code snippet works fine, but the second code snippet with the additional code highlighted in red does NOT. Does anyone know how to fix this? Thanks
FIRST CODE SNIPPET
Code:
Sub Forum_Question()
Dim LR As Long
Dim lc As Integer
Dim colCN As Integer
Dim colTF As Integer
Dim colPA As Integer
Dim i As Integer
'locate columns containing headers
With ActiveSheet
LR = .Cells(.Rows.Count, 1).End(xlUp).Row
lc = .Cells(1, .Columns.Count).End(xlToLeft).Column
For i = 1 To lc
If UCase(.Cells(1, i)) = "CUSTOMER NUMBER" Then colCN = i
If UCase(.Cells(1, i)) = "NAME" Then colTF = i
If UCase(.Cells(1, i)) = "REGION" Then colPA = i
Next i
'Process the active sheet
For i = 2 To LR
If (UCase(.Cells(i, colTF)) = "MARY") _
_
And _
_
((.Cells(i, colPA) <> "East")) _
_
Then
.Cells(i, colPA).Interior.ColorIndex = 3
End If
Next i
End With
End Sub
SECOND CODE SNIPPET
Code:
Sub Forum_Question()
Dim LR As Long
Dim lc As Integer
Dim colCN As Integer
Dim colTF As Integer
Dim colPA As Integer
Dim i As Integer
'locate columns containing headers
With ActiveSheet
LR = .Cells(.Rows.Count, 1).End(xlUp).Row
lc = .Cells(1, .Columns.Count).End(xlToLeft).Column
For i = 1 To lc
If UCase(.Cells(1, i)) = "CUSTOMER NUMBER" Then colCN = i
If UCase(.Cells(1, i)) = "NAME" Then colTF = i
If UCase(.Cells(1, i)) = "REGION" Then colPA = i
Next i
'Process the active sheet
For i = 2 To LR
If (UCase(.Cells(i, colTF)) = "MARY") _
And _
_
((.Cells(i, colPA) <> "East")) _
Or _
((.Cells(i, colPA) <> "South")) _
_
Then _
.Cells(i, colPA).Interior.ColorIndex = 3
End If
Next i
End With
End Sub