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:

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
You need another next after each End If line
 
Upvote 0
You have other problems with the code ColourIndex = should be ColorIndex =
Also I'm not sure the code is going to do what you want.
Can you please explain what you are trying to do?
 
Upvote 0
I am trying to compare two columns such that if column A is Escalation Standby and Column B is Absent then column B should be formatted to a colour red otherwise green
 
Upvote 0
You can do that using conditional formatting like
+Fluff New.xlsm
AB
1
2Escalation Standbyin
3Escalationabsent
4Standbyabsent
5Escalation Standbyabsent
6somethingholiday
7Escalation Standbyholiday
8
9
10
11
Master
Cells with Conditional Formatting
CellConditionCell FormatStop If True
B2:B100Expression=AND(A2="escalation standby",B2="Absent")textNO
B2:B100Expression=B2<>""textNO
 
Upvote 0
what I specifically want to do is combine the five conditions below into one
1. if column A is Escalation Standby and Column B is Absent then column B should be formatted to a colour red otherwise green
2. if column A is Standby and Column B is Absent then column B should be formatted to a colour red otherwise green
3. if column A is attended and Column B is Attended then column B should be formatted to a colour green otherwise red
4, if column A is NA and Column B is Absent then column B should be formatted to colour green otherwise red
5, if column B is absent then column B should be formatted to a red colour
 
Upvote 0
Point 5 is in conflict with point 4 & renders points 1 & 2 irrelevant.
 
Upvote 0
the conditions are listed below:
1. If column A = Escalation Standby and column B=Absent", then background color for column B should be red and if the value is other than "Absent" then the background color is green.

2. If column A = Attend and column B=Absent then the background color for column B should be green, and if the value is NOT "Attend" then the background color is red.
 
Upvote 0

Forum statistics

Threads
1,226,473
Messages
6,191,220
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