Count Occurences of a Cell If It's Less Than

matthewlouis

Active Member
Joined
Mar 28, 2014
Messages
374
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
In my probability analysis spreadsheet, I have a single cell (E10) that contains a %. My goal is to create a counter where, on a mouse click, it will count the number of times cell E10 <=80%.

If I do 30 clicks, 40 clicks, just a simple set of iterations . . . I would like to see the cell count the times those clicks were less <=80%.

What would the formula look like for that?

Thanks in advance!
 
Try this:
VBA Code:
Sub clicky()
for t = 1 to 100
Application.Calculate
Range("G10").Value = Range("G10").Value + 1
If Range("E10").Value <= 0.8 Then Range("G11").Value = Range("G11").Value + 1
debug.print Range("E10").Value
next t
End Sub

and see what ends up in the debug window at the bottom of the VBA window - make sure to show it if it's not there. That will give you a picture of the output - and you might see where it is going wrong.

Maybe you are using 80 for the percentage, and I'm using .8.
 
Upvote 0

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
OK, I modified the algo. I changed percentage to a number and you see 0.45 -- but it wasn't counted.(?)

I am not seeing any of these numbers change when I run the macro -- only the number to 100 runs.
 

Attachments

  • SIMUL.png
    SIMUL.png
    47.6 KB · Views: 6
Upvote 0
Yes, when I put in the Debug.Print line, it didn't show anything in the immediate window except the Range("G10").Value = Range("G10").Value + 1 was YELLOW (see attachment)

There wasn't any verbiage like you're showing in your above post..

That cell (G10) is a link . . . should we have a direct refernce to the worksheet where that calc comes from? Could that be it?

The name of the worksheet for that value is Model but the cell reference is the same.
 

Attachments

  • debug.png
    debug.png
    19.7 KB · Views: 1
Last edited:
Upvote 0
When there is a break in the code (FN+PauseBreak) VBA will highlight the current line of execution. You can hover and see the values - like what t is.

Change the line to
VBA Code:
debug.print t&range("E10").value
 
Upvote 0
When there is a break in the code (FN+PauseBreak) VBA will highlight the current line of execution. You can hover and see the values - like what t is.

Change the line to
VBA Code:
debug.print t&range("E10").value

I changed the line, hit Ctrl-S and got this . . . don't worry about the cell changes as what was E10 is now F13
 

Attachments

  • debugger.png
    debugger.png
    21.3 KB · Views: 2
Upvote 0
THe same odd thing with the semicolon happened to me - put this in:
VBA Code:
Debug.Print t & ":" & Range("E10")
 
Upvote 0
THe same odd thing with the semicolon happened to me - put this in:
VBA Code:
Debug.Print t & ":" & Range("E10")

OK, I updated that line, Ctrl-S, it ran, and then Alt-Q, and I got this.
 

Attachments

  • Debug 1.png
    Debug 1.png
    27.4 KB · Views: 3
Upvote 0
When I try to run macro, it pops up with this.
 

Attachments

  • Debug 2.png
    Debug 2.png
    27.2 KB · Views: 2
Upvote 0
Again, I am noticing the macro is running the 100 iterations . . . . but the numbers are not changing in the boxes, i.e., I don't see 82% or 90% or 96% of 100%, etc... it's like no calculations are occuring to count (?) or is it, I don't know. I do notice as it counts to 100, the bottom of the worksheet is calculating (it's blinking) like something is calculating..
 
Upvote 0

Forum statistics

Threads
1,215,537
Messages
6,125,390
Members
449,222
Latest member
taner zz

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