VBA Loop through a Range with Multiple Conditions

Jaye Cavallo

New Member
Joined
Mar 10, 2022
Messages
45
Office Version
  1. 2016
Platform
  1. Windows
Hello,

I am searching for an Excel VBA solution that would accomplish the following:

I have data in 60 rows in columns A through Z, with the value of column P either "Access" "Noise" or "Notification" and the value of column Q as "open" or "closed". How can I write a VBA loop whereby if P="access" and Q="open" then B through Z has an interior color (NOT formatconditions) set to 26? I want to avoid using VBA Conditional Formatting. My data is contained in A2:Z60 (Named range is Data), column P is a Named range of Reason and column Q is status.

I am searching for a solution that is similar to this code used elsewhere in the worksheet, but code with multiple conditions, if true, change the interior color in multiple cells in a given row.

Dim My_Range As Range
Set My_Range = Worksheets("Customer_Interactions").Range("A2:A3569")

For Each cell In My_Range

If cell.Value Like "Electric" Then
cell.Interior.ColorIndex = 22
ElseIf cell.Value Like "Gas" Then
cell.Interior.ColorIndex = 36
ElseIf cell.Value Like "Other - Specify in Notes" Then
cell.Interior.ColorIndex = 15

Else
cell.Interior.ColorIndex = xlNone

End If

Next
 
I fixed my error. I tried to Set Type_Range. I hadn't noticed your change. Thank you.
 
Upvote 0

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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