VBA code to count under 5% and and non green cells

Reecenorman1996

New Member
Joined
Jul 20, 2023
Messages
31
Office Version
  1. 365
Platform
  1. Windows
Basically i need to count evrything under 5% in column h then if its green on column i i need th minus of exclude the count, the correct figure should be 18

20.00%]-[@Reduction]]£1,000,000
20.00%]-[@Reduction]]£260,000
16.67%]-[@Reduction]]£250,000
16.67%]-[@Reduction]]£1,250,000
15.49%]-[@Reduction]]£300,000
14.29%]-[@Reduction]]£600,000
14.29%]-[@Reduction]]£120,000
14.29%]-[@Reduction]]£3,000,000
13.33%]-[@Reduction]]£325,000
13.04%]-[@Reduction]]£1,000,000
13.04%]-[@Reduction]]£200,000
12.50%]-[@Reduction]]£350,000
11.11%]-[@Reduction]]£2,000,000
11.11%]-[@Reduction]]£40,000
11.11%]-[@Reduction]]£80,000
10.00%]-[@Reduction]]£495,000
10.00%]-[@Reduction]]£90,000
10.00%]-[@Reduction]]£225,000
9.68%]-[@Reduction]]£140,000
9.52%]-[@Reduction]]£190,000
9.09%]-[@Reduction]]£500,000
9.09%]-[@Reduction]]£500,000
9.09%]-[@Reduction]]£500,000
9.09%]-[@Reduction]]£500,000
9.09%]-[@Reduction]]£1,000,000
8.33%]-[@Reduction]]£220,000
8.33%]-[@Reduction]]£110,000
8.33%]-[@Reduction]]£550,000
8.33%]-[@Reduction]]£275,000
8.33%]-[@Reduction]]£1,100,000
8.33%]-[@Reduction]]£550,000
8.33%]-[@Reduction]]£220,000
7.69%]-[@Reduction]]£300,000
7.69%]-[@Reduction]]£300,000
7.69%]-[@Reduction]]£300,000
7.69%]-[@Reduction]]£300,000
7.53%]-[@Reduction]]£430,000
7.41%]-[@Reduction]]£250,000
7.27%]-[@Reduction]]£255,000
7.14%]-[@Reduction]]£650,000
7.14%]-[@Reduction]]£325,000
7.14%]-[@Reduction]]£325,000
7.14%]-[@Reduction]]£260,000
7.14%]-[@Reduction]]£325,000
6.98%]-[@Reduction]]£200,000
6.98%]-[@Reduction]]£2,000,000
6.90%]-[@Reduction]]£270,000
6.82%]-[@Reduction]]£205,000
6.67%]-[@Reduction]]£350,000
6.67%]-[@Reduction]]£700,000
6.67%]-[@Reduction]]£210,000
6.67%]-[@Reduction]]£350,000
6.67%]-[@Reduction]]£350,000
6.67%]-[@Reduction]]£350,000
6.67%]-[@Reduction]]£350,000
6.67%]-[@Reduction]]£350,000
6.67%]-[@Reduction]]£350,000
6.67%]-[@Reduction]]£350,000
6.67%]-[@Reduction]]£280,000
6.67%]-[@Reduction]]£350,000
6.67%]-[@Reduction]]£350,000
6.54%]-[@Reduction]]£500,000
6.40%]-[@Reduction]]£234,000
6.38%]-[@Reduction]]£220,000
6.25%]-[@Reduction]]£375,000
6.25%]-[@Reduction]]£750,000
6.25%]-[@Reduction]]£375,000
6.25%]-[@Reduction]]£375,000
6.25%]-[@Reduction]]£375,000
6.25%]-[@Reduction]]£375,000
6.25%]-[@Reduction]]£375,000
6.00%]-[@Reduction]]£235,000
5.98%]-[@Reduction]]£235,000
5.88%]-[@Reduction]]£800,000
5.88%]-[@Reduction]]£400,000
5.88%]-[@Reduction]]£400,000
5.88%]-[@Reduction]]£400,000
5.88%]-[@Reduction]]£400,000
5.88%]-[@Reduction]]£400,000
5.88%]-[@Reduction]]£400,000
5.88%]-[@Reduction]]£400,000
5.88%]-[@Reduction]]£400,000
5.88%]-[@Reduction]]£400,000
5.88%]-[@Reduction]]£400,000
5.81%]-[@Reduction]]£730,000
5.77%]-[@Reduction]]£245,000
5.71%]-[@Reduction]]£495,000
5.71%]-[@Reduction]]£165,000
5.56%]-[@Reduction]]£170,000
5.56%]-[@Reduction]]£425,000
5.56%]-[@Reduction]]£425,000
5.56%]-[@Reduction]]£425,000
5.56%]-[@Reduction]]£170,000
5.56%]-[@Reduction]]£170,000
5.56%]-[@Reduction]]£425,000
5.56%]-[@Reduction]]£255,000
5.56%]-[@Reduction]]£170,000
5.56%]-[@Reduction]]£425,000
5.56%]-[@Reduction]]£170,000
5.56%]-[@Reduction]]£425,000
5.45%]-[@Reduction]]£260,000
5.45%]-[@Reduction]]£520,000
5.45%]-[@Reduction]]£260,000
5.36%]-[@Reduction]]£265,000
5.26%]-[@Reduction]]£450,000
5.26%]-[@Reduction]]£270,000
5.26%]-[@Reduction]]£450,000
5.26%]-[@Reduction]]£450,000
5.26%]-[@Reduction]]£180,000
5.04%]-[@Reduction]]£565,000
5.00%]-[@Reduction]]£380,000
5.00%]-[@Reduction]]£475,000
5.00%]-[@Reduction]]£199,500
5.00%]-[@Reduction]]£475,000
5.00%]-[@Reduction]]£190,000
5.00%]-[@Reduction]]£190,000
5.00%]-[@Reduction]]£475,000
5.00%]-[@Reduction]]£475,000
5.00%]-[@Reduction]]£475,000
5.00%]-[@Reduction]]£285,000
5.00%]-[@Reduction]]£190,000
5.00%]-[@Reduction]]£950,000
5.00%]-[@Reduction]]£190,000
4.76%]-[@Reduction]]£500,000
4.62%]-[@Reduction]]£310,000
4.55%]-[@Reduction]]£525,000
4.29%]-[@Reduction]]£1,675,000
4.17%]-[@Reduction]]£345,000
4.17%]-[@Reduction]]£575,000
4.17%]-[@Reduction]]£575,000
4.17%]-[@Reduction]]£575,000
4.11%]-[@Reduction]]£700,000
4.00%]-[@Reduction]]£600,000
4.00%]-[@Reduction]]£240,000
4.00%]-[@Reduction]]£360,000
4.00%]-[@Reduction]]£180,000
3.85%]-[@Reduction]]£375,000
3.85%]-[@Reduction]]£500,000
3.85%]-[@Reduction]]£125,000
3.75%]-[@Reduction]]£385,000
3.57%]-[@Reduction]]£675,000
3.57%]-[@Reduction]]£270,000
3.57%]-[@Reduction]]£270,000
3.51%]-[@Reduction]]£275,000
3.45%]-[@Reduction]]£280,000
3.41%]-[@Reduction]]£425,000
3.33%]-[@Reduction]]£290,000
3.23%]-[@Reduction]]£300,000
3.03%]-[@Reduction]]£800,000
3.03%]-[@Reduction]]£800,000
3.03%]-[@Reduction]]£800,000
3.03%]-[@Reduction]]£800,000
2.94%]-[@Reduction]]£825,000
2.86%]-[@Reduction]]£340,000
2.78%]-[@Reduction]]£350,000
2.70%]-[@Reduction]]£900,000
2.70%]-[@Reduction]]£180,000
2.60%]-[@Reduction]]£375,000
2.38%]-[@Reduction]]£410,000
1.69%]-[@Reduction]]£290,000
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
VBA Code:
Sub v()
Dim rng As Range, x&, c&
Set rng = Range([A1], Cells(Rows.Count, "A").End(3))
For x = rng.Count To 1 Step -1
    If rng(x) >= 0.05 Then Exit For
    If rng(x)(1, 2).Interior.Color <> 13561798 Then c = c + 1
Next
MsgBox c
End Sub
 
Upvote 0
VBA Code:
Sub v()
Dim rng As Range, x&, c&
Set rng = Range([A1], Cells(Rows.Count, "A").End(3))
For x = rng.Count To 1 Step -1
    If rng(x) >= 0.05 Then Exit For
    If rng(x)(1, 2).Interior.Color <> 13561798 Then c = c + 1
Next
MsgBox c
End Sub
returning 0 for me do i need to edit any of the data in the code
 
Upvote 0
Select a green cell and check the color number with this code :
VBA Code:
MsgBox Selection.Interior.Color
Are the percentages in column A and the green cells in column B ?
Are the percentages formatted as % ?
 
Upvote 0
Are the green cells the result of conditional formatting ?
 
Upvote 0
Select a green cell and check the color number with this code :
VBA Code:
MsgBox Selection.Interior.Color
Are the percentages in column A and the green cells in column B ?
Are the percentages formatted as % ?
yes % formatted ,percentages in column H green conditional formatted cell in column I
 
Upvote 0
What are the criteria for the conditional formatting?
 
Upvote 0
What are the criteria for the conditional formatting?
1692274674787.png
 
Upvote 0
Can the criteria be : Cell Value >=260,000

And : Cell Value <=7,500,000

Please clarify this : The cell values are in column G and in J1:J154, and the green colors are in column I ?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

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