MsgBox CountIf

julhs

Active Member
Joined
Dec 3, 2018
Messages
471
Office Version
  1. 2010
Platform
  1. Windows
Need some help to understand where I’m going wrong/not understanding the 3rd Count method in my code.
Background info;
Rich (BB code):
The NamedRange is "MyNamedRangeA" and RefersTo A8:A28
Cells A8:A28 contain Array formula
Cells A8:A27 contain the values of the formula
Cell A28 has NO returned value, just the formula
My code to date
VBA Code:
Sub MyTest_CountIF()
Dim rng1 As Range
Set rng1 = Range("MyNamedRangeA")
MsgBox WorksheetFunction.CountIf(Range("A8:A28"), "> """) , "") ' count returns "20"
MsgBox WorksheetFunction.CountIf(Range("MyNamedRangeA "), ">""") ' count returns "20"
MsgBox WorksheetFunction.CountIf(Range("rng1"), ">""") ' count returns "0" and NOT expected "20"
End Sub
As a supplementary observation:
MsgBox WorksheetFunction.CountBlank(rng1) ' count returns "1"
MsgBox WorksheetFunction.CountIf(Range("rng1") , "") ' count returns "1"
which I have to assume !!! is the # of Blanks
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Cells A8:A28 contain Array formula
Cells A8:A27 contain the values of the formula
Cell A28 has NO returned value, just the formula
I can't make sense of this. What is in each of these cells? A formula has to have either a returned value or an error. How can A28 have no returned value, just a formula?

What are you trying to count?

MsgBox WorksheetFunction.CountIf(Range("A8:A28"), "> """) , "") ' count returns "20"
The syntax you are using in this and the subsequent two lines of code don't make sense. You are using the > operator, to determine if the values in the given range are greater than....something. But you are comparing them to a quote " mark. What do you intend to mean by checking if a cell is
Rich (BB code):
>"
?

Also the syntax in your last line is wrong. rng1 is a variable, not a range name
VBA Code:
MsgBox WorksheetFunction.CountIf(Range("rng1"), ">""") ' count returns "0" and NOT expected "20"
should be
VBA Code:
MsgBox WorksheetFunction.CountIf(rng1, ">""") ' count returns "0" and NOT expected "20"
 
Upvote 0
Solution
Thanks for the reply Jeff.
Here is the array formula that’s in the cells $A$8:$A$28 that is the named range "MyNamedRangeA"
Excel Formula:
{=IFERROR(INDEX($B$6:$B$112,SMALL(IF($B$6:$B$112<>"",ROW($B$6:$B$112)-ROW($B$6)+1,""),ROW(A8)-ROW($A$8)+1)),"")}
The formulas pull all the values from a non-contiguous list, $B$6:$B$112 (values are unevenly spaced) and creates a compressed contiguous one in "MyNamedRangeA" range.
The reason for the count is IF there are more values in ($B$6:$B$112) than there are cells with array formula in "MyNamedRangeA" the contiguous list will be incomplete,
so a new row/rows needs to be inserted into "MyNamedRangeA" and the array formula filled down.
If the reverse of that is true I will need to delete a row from "MyNamedRangeA", because I don’t want a cell with null value
My apologies, I messed up here with a copy and paste,
Rich (BB code):
MsgBox WorksheetFunction.CountIf(Range("A8:A28"), "> """) , "") ' count returns "20"
should have read,
Rich (BB code):
MsgBox WorksheetFunction.CountIf(Range("A8:A28"), ">""") ' count returns "20"
Essentially you did pick up my error with,
Rich (BB code):
MsgBox WorksheetFunction.CountIf(Range("rng1"), ">""") ' count returns "0" and NOT expected "20"
needing to be,
Rich (BB code):
MsgBox WorksheetFunction.CountIf (rng1, ">""")
I had run tests on so many different variations I somewhat lost sight of things.
And my supplementary observation didn’t do anything other than add to my confusion
Rich (BB code):
MsgBox WorksheetFunction.CountIf(Range("rng1") , "") ' count returns "1" which I have to assume !!! is the # of Blanks
Many thanks for your assistance, very much appreciated and sorry for the confusion I created.
julhs
 
Upvote 0

Forum statistics

Threads
1,223,575
Messages
6,173,151
Members
452,503
Latest member
AM74

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