Test if certain ranges of cells have a specific color

fddekker

Board Regular
Joined
Jun 30, 2008
Messages
86
Office Version
  1. 365
Platform
  1. Windows
This is my code for a simple test that the macro will only run on a specific imported file. The constants in the files that will be transformed are the cell colors in Cells A7 to C8, with row 7 Blue and row 8 yellow.

I have tried several variations of testing for the cell colors, but keep on getting a syntax error on line 1. here is the code that I feel is the most concise:

Sub Macro1()
If Interior.Color(A7:C7) <> RGB(93, 203, 253) Or Interior.Color(A8:C8) <> RGB(254,254,184) Then
MsgBox "This procedure is for the xxxxxI file only. This does not seem to be the correct report"
Exit Sub
End If
MsgBox "This is the correct report"
End Sub

Any help on where I am going wrong would be appreciated.
 

Attachments

  • 1629907873522.png
    1629907873522.png
    1.6 KB · Views: 5

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Try

Code:
Sub aTest()
    If Range("A7:C7").Interior.Color <> RGB(93, 203, 253) Or Range("A8:C8").Interior.Color <> RGB(254, 254, 184) Then
        MsgBox "This procedure is for the xxxxxI file only. This does not seem to be the correct report"
        Exit Sub
    End If
        MsgBox "This is the correct report"    
End Sub

M.
 
Upvote 0
Solution

Forum statistics

Threads
1,215,064
Messages
6,122,939
Members
449,094
Latest member
teemeren

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