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:
Is the code in a userform (would explain the error) or a worksheet code module?
 
Upvote 0

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
It has to be in a code module (it is code, after all ;)), I'm asking which one - worksheet or userform?
 
Upvote 0
It has to be in a code module (it is code, after all ;)), I'm asking which one - worksheet or userform?

Oops! My bad! It's in a worksheet module.

In the meantime, I went back to the UsedRange and changed Me to ActiveSheet. It seems to have gotten thru but then got a Run-time error '424' at this point in the code:

Rich (BB code):
'Prevents endless loops
Application.EnableEvents = False
 'They have more than one cell selected
 If Target.Cells.Count > 1 Then
    Application.EnableEvents = True
    Exit Sub
 End If
 If Target.Column <> 7 Then
    Application.EnableEvents = True
    Exit Sub
End If
 If WorksheetFunction.CountA(Target.EntireRow) <> 0 Then
    ActiveSheet.UsedRange.Sort Key1:=[A2], Order1:=xlAscending, _
    Header:=xlYes, OrderCustom:=1, MatchCase:=False, _
    Orientation:=xlTopToBottom
    Application.EnableEvents = True
 End If
 Application.EnableEvents = True ' just to make sure events get turned on again.
End Sub
 
Last edited by a moderator:
Upvote 0
If it's in a worksheet module, you shouldn't get an error on Me.Usedrange since all worksheets have a Usedrange property.

Also, please use CODE tags, not QUOTE tags, when posting code.
 
Last edited:
Upvote 0
If it's in a worksheet module, you shouldn't get an error on Me.Usedrange since all worksheets have a Usedrange property.

Also, please use CODE tags, not QUOTE tags, when posting code.

Again, apologies!

It's happening as soon as I 'click' my button to get the info on the sheet. It stops at "Private Sub NewRec_Click()" and highlights it in yellow along with the ".UsedRange" in blue. So it's not even starting the Sub yet!

P.S. I did change it back to Me.UsedRange; causing this last error, not the Run-time error now!
 
Last edited:
Upvote 0
I've been so caught up in trying to get this thing working that I didn't even notice that I was working with someone else now! Just a shot in the dark here; does the fact that I don't have a loop to clear the form after putting it into the sheet?? I am an "old" noob at this but wanting to learn and understand whats going on!
 
Upvote 0
Is this code for the button on your user form? If so Me would cause problems as it is not the worksheet, which is what you want the code to act on.

You will also have a problem with using Target as it will be nothing. Some workbook events like a Change event will have
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Target will be the cell that was changed if you are using a event that does not have a target or a button then there is no target for the code to use.
 
Upvote 0
Is this code for the button on your user form? If so Me would cause problems as it is not the worksheet, which is what you want the code to act on.

You will also have a problem with using Target as it will be nothing. Some workbook events like a Change event will have
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Target will be the cell that was changed if you are using a event that does not have a target or a button then there is no target for the code to use.

No sir, it is on the worksheet code module, "Private Sub NewRec_Click()".
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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