Counting coloured cells

jarhead58

Active Member
Joined
Sep 21, 2017
Messages
364
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
4Blue or not

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</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
11Some Num

<tbody>
</tbody>
Sheet2
 
Last edited:
Is the code in a userform (would explain the error) or a worksheet code module?
 
Upvote 0

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
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,215,966
Messages
6,127,977
Members
449,414
Latest member
sameri

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