Substring function not working as expected

ufotje

New Member
Joined
Oct 23, 2020
Messages
10
Office Version
  1. 2016
Platform
  1. Windows
I wrote a function to see if the value of a specific field contains a substring based on that it's suposed to do one of two things, this is the formula:
Excel Formula:
=IF(ISTEXT(SEARCH("Withdrawal for KNC*"; A7));E7+L6;L6)
, as you might be able to guess I wanna calculate all the withdrawals for KNC, E7 contains the amount L6 is the subtotal, so when the substring is found it should add E7 to L6 and write it in L7(the cell of the function), I wrote it in the first cell and then just pulled it down so it could autocomplete, the first 3 cell work great, but then I get unexpected behaviour, I was hoping someone could tell me why, online I see everyone searching for a substring with ISNUMBER instead of ISTEXT, but when I try that is returns false even when the substring is pressent.
These are some values to show what i mean with unexpected behaviour


Action (Column A)
(this is the field I search for the substring)
DateTimeStart BalanceAmount (Column E)
(this is the amount to be added)
New BalanceDescriptionTotal Withdrawals KNC
(Column L)
Deposit for KNC on Kucoin21 OCTOBER 202000:05:181300014488,5540427488,55404Buy0
Withdrawal for BTC on Kucoin21 OCTOBER 202000:05:183-12payed for KNC0
Withdrawal for KNC on Kucoin21 OCTOBER 202000:05:1827488,55404-14,4885540427474,06549TakerFee KNC-14,48855404
Withdrawal for KNC on Kucoin21 OCTOBER 202000:05:1827474,06549-2,8427471,22549WithdrawFee KNC-17,32855404
Withdrawal for KNC on Kucoin21 OCTOBER 202000:05:1827471,22549-14471,2254913000Transfer to Binance-14488,55404
Deposit for KNC on Binance21 OCTOBER 202000:05:181300014471,2254927471,22549Transfer from Kucoin-17,32855404
(unexpected value should be -14488,55404)
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Welcome to the Board!
why, online I see everyone searching for a substring with ISNUMBER instead of ISTEXT,

You want to use ISNUMBER, not ISTEXT. It does not matter what you are searching for (whether it is text or number), the SEARCH function returns a number, specifically tha position within the string that the substring you are looking for starts at. So if it finds it, it will return a number. If it does not find it, it will return an error. That is why you want to use ISNUMBER.
 
Upvote 0
Welcome to the Board!


You want to use ISNUMBER, not ISTEXT. It does not matter what you are searching for (whether it is text or number), the SEARCH function returns a number, specifically tha position within the string that the substring you are looking for starts at. So if it finds it, it will return a number. If it does not find it, it will return an error. That is why you want to use ISNUMBER.
As I said in my first post, when I use IsNumber, it always return false, even when the text is part of the string
 
Upvote 0
First off, get rid of the asterisk. There is no need to have that when searching for a substring.

If I have this in cell A7:
Rich (BB code):
Withdrawal for KNC on Kucoin
Then If I enter this formula:
Excel Formula:
=SEARCH("Withdrawal for KNC";A7)
it returns "1" for me.
Does it not do this for you?
 
Upvote 0
I didn't try =Search(...), I tried IF(IsNUMBER(SEARCH(...))...) and that didn't work
 
Upvote 0
I didn't try =Search(...), I tried IF(IsNUMBER(SEARCH(...))...) and that didn't work
The way to debug these things is to start from the inner most single function, and then work your way out, one function at a time.
We start with just SEARCH first, and then when that is working we can add the next step. (ISNUMBER).

So can you please try that and tell us what happens?
 
Upvote 0
if i remove the asterix the function dosn't work eather
 
Upvote 0
Please try what I asked you up in post 4 and tell me EXACTLY what the formula returns.
 
Upvote 0
When I use seracht("", A4) it returns the substring starting from the second character
 
Upvote 0
not the substring but the whole string;, when I then change it =ISNUMBER(SEARCH("With...", A7)) I get false
 
Upvote 0

Forum statistics

Threads
1,215,012
Messages
6,122,682
Members
449,091
Latest member
peppernaut

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