how do i solve the for without next error i keep getting

pveke

New Member
Joined
Sep 12, 2020
Messages
9
Office Version
  1. 2013
Platform
  1. Windows
VBA Code:
Dim aRng, bRng As Range
Set aRng = Range("AC5:A175")
Set bRng = Range("AD5:AD175")

For Each aCell In aRng
    For Each bcell In bRng
    If aCell Like "true" And bcell Like "false" Then
         bcell.Interior.ColourIndex = 3
           Else: bcell.Interior.ColourIndex = 10
    End If
Next
For Each cCell In aRng
    For Each dcell In bRng
    If cCell = "yes" And dcell = "no" Then
           dcell.Interior.ColourIndex = 3
            Else: dcell.Interior.ColourIndex = 10
    End If
Next
For Each eCell In aRng
    For Each fcell In bRng
    If eCell Like "good" And fcell Like "bad" Then
           fcell.Interior.ColourIndex = 10
            Else: fcell.Interior.ColourIndex = 3
    End If
Next
For Each gCell In aRng
    For Each hcell In bRng
    If gCell Like "N/A" Then
           hcell.Interior.ColourIndex = 10
    End If
Next
For Each iCell In aRng
    For Each jcell In bRng
    If jcell Like "sucks" Then
           jcell.Interior.ColourIndex = 3
    End If

Next
End Sub
 
Last edited by a moderator:
So if column B is Absent it should be red unless col A is Attend & if col B is anything other than absent it should be green. Is that correct?
 
Upvote 0

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
this is my code and i keep getting a runtime error 438

Sub conditional_formatting()
Dim aRng, bRng As Range
Set aRng = Range("AC5:A175")
Set bRng = Range("AD5:AD175")

For Each acell In aRng
For Each bcell In bRng
If acell Like "Escalation Standby" And bcell Like "Absent" Then
bcell.Interior.ColourIndex = 3
Else: bcell.Interior.ColourIndex = 10

End If
Next
Next
For Each ccell In aRng
For Each dcell In bRng
If ccell = "Standby" And dcell = "Absent" Then
dcell.Interior.ColourIndex = 3
Else: dcell.Interior.ColourIndex = 10
End If
Next
Next
For Each ecell In aRng
For Each fcell In bRng
If ecell Like "Attend" And fcell Like "Attend" Then
fcell.Interior.ColorIndex = 10
Else: fcell.Interior.ColourIndex = 3
End If
Next
Next
For Each gcell In aRng
For Each hcell In bRng
If gcell Like "N/A" Then
hcell.Interior.ColourIndex = 10
End If
Next
Next
For Each icell In aRng
For Each jcell In bRng
If jcell Like "Absent" Then
jcell.Interior.ColourIndex = 3
End If

Next
Next

End Sub
 
Upvote 0
Can you please answer my question in post#11?
 
Upvote 0
Ok, how about
VBA Code:
Sub conditional_formatting()
   Dim Cl As Range
   
   For Each Cl In Range("AD5:AD175")
      If LCase(Cl.Value) <> "absent" Then
         Cl.Interior.ColorIndex = 10
      ElseIf LCase(Cl.Offset(, -1).Value) <> "attend" Then
         Cl.Interior.ColorIndex = 3
      End If
   Next Cl
End Sub
 
Upvote 0

Forum statistics

Threads
1,226,475
Messages
6,191,226
Members
453,648
Latest member
graduateguardian

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top