Counting coloured cells

jarhead58

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

Title says it all! Here's what I'm trying to do! Let me know if this can be done! TIA!!

GHIJKLMNOP

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
[TD="align: center"]4[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=0F6FC6]#0F6FC6[/URL] , align: right"][/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] , align: right"][/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=0F6FC6]#0F6FC6[/URL] , align: right"][/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] , align: right"][/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=0F6FC6]#0F6FC6[/URL] , align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: center"]Blue or not[/TD]

</tbody>
Sheet2

If G3:K3 is blue count it. If qty is 3, G11=a number, 4=another number…
OR if P3 and G3:K3 is blue and qty is >=2, G11=this number

G
Some Num

<tbody>
[TD="align: center"]11[/TD]

</tbody>
Sheet2
 
Last edited:
Hmm, still not doing it. I put the code in the immediate window. Just for giggles, I even changed the range from "B2:G2", where I enter info via form, to "V14:AA14", where it changes cell color, still nothing. I also saved and restarted excel and the project.

FYI the code is in the "Worksheet" "Change" window!
 
Last edited:
Upvote 0

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Put this in a module and run it. Do you get true?
Code:
Sub events()
If Application.EnableEvents = False Then
    MsgBox "FALSE"
Else: MsgBox "TRUE"
End If
End Sub
 
Upvote 0
If events are enabled then the code is running but not doing what you want.
Put stop at the start of the code this will stop the code from running. Then you can step though the code (press F8 to go to the next line of code) and see where the code goes the line about to run will be highlighted in yellow. Does the code execute like you expect? That is when a cell that is not in the range B2:G2 is changed it should jump down to the End If right before your sort code. If the cell changed is in the range it should run the count cells code.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

[COLOR=#FF0000]Stop[/COLOR]
If Not Intersect(Target, Range("B2:G2")) Is Nothing Then
Application.EnableEvents = False
 
Upvote 0
Put the Stop in but it evidently isn't getting to the code! I saved and restarted again, put in new info via the form but nothing. One thing I forgot about was the actual change doesn't happen until I do the Newest to oldest sort to bring it to B2:G2. Not sure if that makes a difference or not.
 
Upvote 0
The code should always run when there is a change to the sheet. It may not do anything if the conditions but it should run. What sheet is the code on and what sheet is the range B2:G2 that you want to check on?

Is the sort the one in your change event or is it different code?
 
Upvote 0
The code should always run when there is a change to the sheet. It may not do anything if the conditions but it should run. What sheet is the code on and what sheet is the range B2:G2 that you want to check on?

Is the sort the one in your change event or is it different code?

It's all on Sheet1 and I just do a manual Sort after closing the form!
 
Upvote 0
Sorting does not trigger the change event. You should be able to add code to your user form to sort on close and then run the count colors code.

You can use the macro recorder to record the sort and then add the code to you user form. It may require some tweaks if the range is dynamic.
 
Upvote 0
The form is just the basic form mode that just gives you input boxes, previous record, next, etc., nothing customized.
 
Upvote 0
You would have to add the code to the form or you can run the count color code manual after sorting the spread sheet.
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,204
Members
453,022
Latest member
RobertV1609

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