If cell color...

jarhead58

Active Member
Joined
Sep 21, 2017
Messages
367
Office Version
  1. 2021
Platform
  1. Windows
Hello all!

I thought this was going to be simple, and maybe it really is, but I can't seem to find the answer! I'm just looking for something to increment my count! Something like, " If R12(Interior.Color=12611584) Then count=count+1
Help is definitely appreciated!!
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Is this what you're after
Code:
If Range("R12").Interior.Color = 12611584 Then Count = Count + 1
 
Upvote 0
Is this what you're after
Code:
If Range("R12").Interior.Color = 12611584 Then Count = Count + 1

That's what I thought would work earlier but it didn't work. Here's what I have in my code.

Code:
For Each cell In Range("M12:Q12")
            If cell.DisplayFormat.Interior.Color = 12611584 Then
            mycount = mycount + 1
                    If Range(R12).Interior.Color = 12611584 Then
                   mycountplus = 4
            Else
            End If
        End If
Next cell
 
Last edited:
Upvote 0
Changed the Range from M12:Q12 to M12:R12, just in case! No good!
 
Upvote 0
Code:
Sub My_Count()
Dim mycount As Long
Dim mycountplus As Long
Dim cell As Range
mycount = 0
mycountplus = 0
    For Each cell In Range("M12:Q12")
            If cell.DisplayFormat.Interior.Color = 12611584 Then mycount = mycount + 1
    Next cell
    If Range("R12").Interior.Color = 12611584 Then mycountplus = 4
MsgBox "mycount total is " & mycount
MsgBox "mycountplus total is " & mycountplus
End Sub
 
Last edited:
Upvote 0
My answer is..
Thanks! That works with a minor correction of "If Range("R12").DisplayFormat.Interior.Color....."!! I really appreciate your help!! Saved me from pulling what hair I have left out lol!! Thanks again!! You guys Rock!!
 
Last edited:
Upvote 0
I do not know what you mean about by code being correct but. Your original script included R12 in a loop looking in a range that did not include R12. My script wrote that line of code outside the loop
My answer is..
Thanks! That works with a minor correction of "If Range("R12").DisplayFormat.Interior.Color....."!! I really appreciate your help!! Saved me from pulling what hair I have left out lol!! Thanks again!! You guys Rock!!
 
Upvote 0
No, I meant that you left off the DisplayFormat on the R12 in the original If statement that you gave me!! Thanks again!!
 
Upvote 0
No, I meant that you left off the DisplayFormat on the R12 in the original If statement that you gave me!! Thanks again!!
He left it off because you did not show it in the code you posted in Message #3 ... all he did was correct the code you posted.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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