Count if or VBA or Code

Vishaal

Well-known Member
Joined
Mar 16, 2019
Messages
533
Office Version
  1. 2010
  2. 2007
Platform
  1. Windows
  2. Web
Hi All,

Thanks in advance for your help.

we have the following sheet, its a sample sheet (have data approx 90 row and 100 column)

Excel 2010 32 bit
A
B
C
D
E
F
1
Marks​
Ram​
Ravi​
Rozi​
Sunny​
Ahmed​
2
45​
Na​
Na​
Na​
Na​
Na​
3
65​
Na​
Na​
Na​
Na​
Na​
4
25​
Yes​
Yes​
Yes​
Yes​
Yes​
5
35​
Na​
Na​
Na​
Na​
Na​
6
26​
Yes​
Yes​
Yes​
Yes​
Na​
7
98​
Na​
Na​
Na​
Na​
Na​
8
78​
Na​
yes​
Na​
Na​
Na​
9
15​
Na​
Na​
yes​
Na​
Na​
10
45​
Na​
Na​
Na​
yes​
Na​
Sheet: Sheet1



Need the following result

Excel 2010 32 bit
A
B
C
D
E
F
1
Marks​
Ram​
Ravi​
Rozi​
Sunny​
Ahmed​
2
45​
Na​
Na​
Na​
Na​
Na​
3
65​
Na​
Na​
Na​
Na​
Na​
4
25​
Yes​
Yes​
Yes​
Yes​
Yes​
5
35​
Na​
Na​
Na​
Na​
Na​
6
26​
Yes​
Yes​
Yes​
Yes​
Na​
7
98​
Na​
Na​
Na​
Na​
Na​
8
78​
Na​
yes​
Na​
Na​
Na​
9
15​
Na​
Na​
yes​
Na​
Na​
10
45​
Na​
Na​
Na​
yes​
Na​
11
12
Total "Na" in continuation from bottom​
4​
2​
1​
6​
13
14
Sheet: Sheet1

We have counted Total "Na" which are in continuation from bottom. After this we want to compare
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Here is a UDF (user defined function) that you can use...
Code:
Function CountNA(Rng As Range) As Variant
  Dim Arr As Variant
  Arr = Split(Join(Application.Transpose(Rng), ""), "yes", , vbTextCompare)
  CountNA = Len(Arr(UBound(Arr))) / 2
  If CountNA = 0 Then CountNA = ""
End Function

HOW TO INSTALL UDFs
------------------------------------
If you are new to UDFs, they are easy to install and use. To install it, simply press ALT+F11 to go into the VB editor and, once there, click Insert/Module on its menu bar, then copy/paste the above code into the code window that just opened up. That's it.... you are done. You can now use CountNA just like it was a built-in Excel function. For example,

=CountNA(B2:B10)

If you are using XL2007 or above, make sure you save your file as an "Excel Macro-Enabled Workbook (*.xlsm) and answer the "do you want to enable macros" question as "yes" or "OK" (depending on the button label for your version of Excel) the next time you open your workbook.
 
Upvote 0
Thanks for the help Rick Rothstein Sir Ji,

i have used the formula but its not giving accurate result, check in below sheet

Excel 2010 32 bit
A
B
C
D
E
F
1
First Data​
2
Marks​
Ram​
Ravi​
Rozi​
Sunny​
Ahmed​
3
45​
Na​
Na​
Na​
Na​
Na​
4
65​
Na​
Na​
Na​
Na​
Na​
5
25​
Yes​
Yes​
Yes​
Yes​
Yes​
6
35​
Na​
Na​
Na​
Na​
Na​
7
26​
Yes​
Yes​
Yes​
Yes​
Na​
8
98​
Na​
Na​
Na​
Na​
Na​
9
78​
Na​
yes​
Na​
Na​
Na​
10
15​
Na​
Na​
yes​
Na​
Na​
11
45​
Na​
Na​
Na​
yes​
Na​
12
13
Total "Na" in continuation from bottom
4​
2​
1​
6​
14
15
16
17
with your instructions
3
1
3
5
Sheet: Sheet1

Help pls
 
Upvote 0
When my example showed this formula to use...

=CountNA(B2:B10)

the range was based on the data you posted in Message #1 ... the data you posted in Message #3 has everything one row lower. So the data you want to count is no longer in the range B2:B10 for the first column... you moved it to B3:B11 so the formula you must use is this...

=CountNA(B3:B10)

The formula cannot figure out on its own where your data is... you must tell it. So, if you add more rows of data, you will have to adjust the range given to the UDF so it knows where the data it has to parse is located at.
 
Last edited:
Upvote 0
Thanks for the help Rick Rothstein Sir Ji,

I am really sorry for not read carefully, really sorry

its working

Thanks
 
Upvote 0

Forum statistics

Threads
1,214,390
Messages
6,119,235
Members
448,879
Latest member
VanGirl

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