Mix IF and MID

tinferns

Board Regular
Joined
Aug 18, 2009
Messages
150
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
Hi,
Can I mix IF with MID command?

I am trying a formula which is not working the way it should. Can you please help me ?

Q16 = 1, 0, 3, 7, 2 (I will have numbers between 1-9 in random order) I want to count all numbers above 1 (I dont want SUM). In this case I want result to be 4. (By COUNTing 1, 3, 7, and 2)

I tried : =IF(MID(Q16,1,1)>1,1)+IF(MID(Q16,4,1)>1,1)+IF(MID(Q16,7,1)>1,1)+IF(MID(Q16,10,1)>1,1)+IF(MID(Q16,13,1)>1,1,0)

I am getting result 5. Wherein it is even counting for a Zero. I want to count only 1-9.

Can you help me

Thanks in advance.

Martin
 
<DIR>Hi PGC,
I had a small error in my query...
earlier I had mentioned that they will be max 7 cases with numbers from 0-9. Actually the case is max 7 cases with numbers from 0 - 365. So we can have cases like below:

1, 0, 343, 8, 10

In case of the above the result should be 4.

Current formula is double calculating any number over 9.. And the result shown is 7 for the above case.

<DIR>=LEN(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1," ",""),",",""),"0",""))

Can this be tweaked to meet my new requirement ?
Please advise..

Sorry for the confusion.

Thanks in advance

Martin.
</DIR></DIR>
 
Upvote 0

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Hi Martin

There may be easier formulas, try:

=SUM((LEN(SUBSTITUTE(","&A3," ",""))-LEN(SUBSTITUTE(SUBSTITUTE(","&A3," ",""),{",",",0"},"")))*{1,-0.5})

You could also write a vba snippet or use one from one add-in. Aladin already gave a solution following that approach.
 
Upvote 0
An easier version of the formula:

=LEN(SUBSTITUTE(", "&A1,", 0",""))-LEN(SUBSTITUTE(SUBSTITUTE(", "&A1,", 0",""),",",""))

The difference is that this formula assumes that between 2 numbers there's always exactly 1 comma and one space. The formula in the previous post allowed any number of spaces.
 
Upvote 0
Thanks PCG,

This formula works just fine.. thanks a million.. cheers.... Martin
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

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