I want to check if the second digit in a number is 0
Example:
101 --> yes
605 --> yes
234 --> no
I wrote this formula
=IF(AND(C9>100;C9<909;VALUE(MID(C9;2;1))=0);"Yes";"No")
when the number I'm checking is less than 12 I get a #Value error. I know it has to do with MID, but I thought that the first 2 conditions are calculated first.
#Value error come from VALUE function feed invalid text so it can generate valid result, good news is it can be removed in this case, but 0 must be quoted so treated as text
=IF(AND(C9>100;C9<909;MID(C9;2;1)="0");"Yes";"No")
Related
Given a list of numbers I am trying to find the next odd or even number from the list given a specified number. The specified number doesn’t have to be in the range. For ex:
I am given number 406, I am suppose to find the next even or odd value from it from the given list of numbers:
380
381
382
383
385
400
401
403
407
410
411
0
0
0
0
In this case the next even returned should be 410 and the next odd returned should be 407.
In the case that specified number is in that list then it should return the next even or odd number from it.
I am doing this in excel and trying to create a UDF that can perform this task but nothing to any avail. Any help would be greatly appreciated.
There's no need for VBA here:
If your version of Excel supports FILTER, for even use:
=#FILTER(A1:A15,(A1:A15>406)*(MOD(A1:A15,2)=0))
and change the 0 to 1 for odd.
If you don't have FILTER, then for even:
=AGGREGATE(15,7,A1:A15/((A1:A15>C1)*(MOD(A1:A15,2)=0)),1)
where the comparison number is stored in C1. Similarly change 0 to 1 for odd.
I have Excel sheet with value and another column value that depend of theme
If value >48 the value will be 8 if <=40 value will be 0 if value inferior a 48 and supperieru a 40 value will be column -40 I tried this but didn't work
=SI(AH15>48,8,SI(ET(AH15>40,AH15<48,AH15-40))
Or english:
=IF(AH15>48,8,IF(AND(AH15>40,AH15<48,AH15-40))
You are throwing in an AND function to check multiple conditions in a wrong manner:
All these conditions ET(AH15>40,AH15<48,AH15-40) can never be true since the last parameter is a calculation. Either way, what you tried to do is maybe:
=SI(AH15<=40,0,SI(AH15>48,8,AH15-40))
Which translates to:
=IF(AH15<=40,0,IF(AH15>48,8,AH15-40))
Try this one:
=IF(AH15>48,8,IF(AND(AH15>40,AH15<=48),AH15-40,0))
Hope it helps
I'm trying to get a sum on a column using VBA and in doing so any variation of Application.Sum is resulting in incorrect output.
Somewhere I read that this issue might occur if my datatype is considered as text, so I updated the whole column to be Number, yet my issue with case 1 persisted.
'Case 1 - Incorrect result # 15.67 for a whole column of 341 1's
ActiveSheet.Range("L1").Value = Application.Sum(Range("E1").EntireColumn)
'Case 2 - Returns correct result # 341
ActiveSheet.Range("L2").Formula = "=sum(E:E)"
Can someone please explain why the output in Case 1 is incorrect compared to Case 2 which is a straightforward code
I am trying to segment Customer with RFM Segmentation ranged 1 to 5 for each column R, F and M. After I combined the three column, there are many possibilities such as 151, 555, or 254 and so on.
Code 555 is the best Customer
and X5X is the loyal customer. "X" defines any numbers, e.g Code 454 is also Loyal Customer segmentation.
The problem is i cannot exactly deliver the IF function in excel correctly. Here is my trial for 555
=IF(O14="555","Best Customer",IF(MID(O14,2,1)="5","Loyal Customer"))
The function overlaps since it took the latest IF, so the result for 555 is Loyal Customer which should be Best Customer. There are many segmentation such as XX5 for the big spenders, however since the formula turns to overlap i cannot continue the rest. Thank you for your help.
If you only want 1 result per number, then you just need to put the highest priority first. The first IF that is TRUE will be the one that is used. From your example, it looks like "455" would be both a Loyal Customer and a Big Spender. We can't tell from your explanation what the result should be in this case. But whichever is the higher priority should just come earlier in your nested IF statements.
Your formula looks correct that 555 should return "Best Customer". If it is returning Loyal Customer, then it seems like you've got 555 stored as a number rather than text in O14. If it is a number, your formula should instead be:
=IF(O14=555,"Best Customer",IF(MID(O14,2,1)="5","Loyal Customer"))
The only difference is removing the quotes around 555. If O14 is stored as a number, then O14="555" is comparing a number to a string (three "5" characters rather than the number 555), which will always return FALSE, hence it moves on the next IF statement. To get a TRUE result at the start, you need to compare O14 to the number 555 instead.
You may then be confused about why the 2nd part of the formula works. This is because the MID function will accept a number as input and then force a type conversion.
When you use the = operator, excel can only compare like values. Meaning it can compare strings to strings or numbers to numbers, but not strings to numbers.
However, the MID function will accept either strings or numbers. When it is given a number, it will first convert it to a string and then output a string.
If it is given MID(555,2,1), it first changes 555 to "555" and gives the same result as MID("555",2,1), which is the character "5" rather than the number 5.
So, even if O14 has the number 555, MID(014,2,1) will return the character "5" and the comparison MID(O14,2,1)="5" will return TRUE.
I placed an example below, of which I don't necessarily 'need' to work, but I don't like that I can't get it to work. I've attempted to use the ISNA function, but am having little success since I
=IF(VLOOKUP(H3,Credit!H:J,3,FALSE)=(J3*-1),"Please Purge",IF(VLOOKUP(H3,Credit!H:J,3,FALSE)<(J3*-1),"Not enough Credit... research",IF(VLOOKUP(H3,Credit!H:J,3,FALSE)<(J3*-1),"Additional Credit… Research","No Credit Exists")))
I really would like to have a response to each formula, am I using the wrong functions or the wrong format?
To avoid repeating the VLOOKUP function multiple times you can use SIGN and CHOOSE in this scenario like this
=CHOOSE(SIGN(VLOOKUP(H3,Credit!H:J,3,FALSE)+J3)+2,"Not enough Credit... research","Please Purge","Additional Credit… Research")
If you add the VLOOKUP result to J3 you will get a negative number, zero or a positive number, SIGN function will return -1, 0 or 1 respectively for those and then adding 2 gives 1, 2 or 3 so we can use CHOOSE function to convert 1,2 or 3 to the relevant text value
That formula still gives #N/A error if H3 isn't found in Credit!H:H so to avoid that use IFERROR function (assumes Excel 207 or later), so final version becomes:
=IFERROR(CHOOSE(SIGN(VLOOKUP(H3,Credit!H:J,3,FALSE)+J3)+2,"Not enough Credit... research","Please Purge","Additional Credit… Research"),"No credit exists")
perhaps
=IF(ISNA(MATCH(H3,Credit!H:H,0)),"No Credit Exists",IF(VLOOKUP(H3,Credit!H:J,3,FALSE)=(J3*-1),"Please Purge",IF(VLOOKUP(H3,Credit!H:J,3,FALSE)<(J3*-1),"Not enough Credit... research","Additional Credit… Research")))
the MATCH part looks for the value H3 in Credit!H:H and if it isn't there the ISNA handles the resulting error and returns "No credit exists"; the rest is basically just a tweak of the original formula