Check to see if cell contains 2 spaces directly after each other - excel

Is there a way that I can check to see if my cell contains 2 spaces immediately after one another?
For example if my cell contained "The cat went meow" then my formula below will return "No" because there is only one space between each character. However, if there where 2 spaces like
"The cat went meow"
then the formula would return "Yes".
I have tried the following formula but it picks up all the spaces instead of what I want it to do.
Can someone please show me how i could correct this?
=IF(ISNUMBER(SEARCH(" " & " ",B1)),"Yes","no")

Might be worth considering TRIM():
=LEN(B1)=LEN(TRIM(B1))
Test cases:
"The cat went meow" TRUE (single space)
"The cat went meow" FALSE (double space)
" The cat went meow" FALSE (leading space)
"The cat went meow " FALSE (trailing space)
this works for your example, if allowance is made for returning T/F rather than Y/N (to keep the formula short - Y/N could be arranged).
A better (shorter) version was offered by #Rick Hitchcock (to whom thanks) in a Comment:
=B1=TRIM(B1)
However it would return FALSE not only for "double" spaces but any quantity of spaces that are not on their own (immediately next to characters on both sides)
and
it would return FALSE even for single spaces if at the start and/or end of your string.
So this is not exactly what you asked for, and no more, but in practice seems likely to be more useful in general.

Your code works for me as-is. You could simplify it like this:
=IF(ISNUMBER(SEARCH(" ",B1)),"Yes","no")
To avoid error-checking, you could compare the string to a version with double-spaces converted to spaces, like this:
=IF(SUBSTITUTE(B1," "," ")<>B1,"Yes","no")
But I'm unsure what problem you're having with your existing code.

Try this
=IF(ISERROR(FIND(" ",B1,1)),"No","Yes")
or
=IF(ISERROR(SEARCH(" ",B1,1)),"No","Yes")

Related

Combining 6 IF formulas

I've written 6 different IF formulas, each will identify a freight carrier based on the tracking number found in cell BM71.
For the life of me I cannot figure out how to combine these, any help would be appreciated.
=IF(AND(LEN(BM71)=18,LEFT(BM71,2)="1Z"), "UPS", "")
=IF(AND(LEN(BM71)=12,ISNUMBER(BM71)),"FedEx","")
=IF(AND(LEN(BM71)=10,ISNUMBER(BM71)),"DHL","")
=IF(AND(LEN(BM71)=11,LEFT(BM71,2)="06"), "Old Dominion", "")
=IF(AND(LEN(BM71)=9,LEFT(BM71,2)="00"), "Arcbest", "")
=IF(AND(LEN(BM71)=10,LEFT(BM71,2)="00"), "Averitt", "")
With ifS function it gets more clean:
=IFs(AND(LEN(BM71)=18,LEFT(BM71,2)="1Z"), "UPS",
AND(LEN(BM71)=12,ISNUMBER(BM71)),"FedEx",
AND(LEN(BM71)=10,ISNUMBER(BM71)),"DHL",
AND(LEN(BM71)=11,LEFT(BM71,2)="06"), "Old Dominion",
AND(LEN(BM71)=9,LEFT(BM71,2)="00"), "Arcbest",
AND(LEN(BM71)=10,LEFT(BM71,2)="00"), "Averitt",
True,"")
You just add a new IF in the False part. Like this:
=IF(AND(LEN(BM71)=18,LEFT(BM71,2)="1Z"), "UPS",
IF(AND(LEN(BM71)=12,ISNUMBER(BM71)),"FedEx",
IF(AND(LEN(BM71)=10,ISNUMBER(BM71)),"DHL",
IF(AND(LEN(BM71)=11,LEFT(BM71,2)="06"), "Old Dominion",
IF(AND(LEN(BM71)=9,LEFT(BM71,2)="00"), "Arcbest",
IF(AND(LEN(BM71)=10,LEFT(BM71,2)="00"), "Averitt", ""))))))
No love for LET?
Something like:
=LET(x,BM71,l,LEN(x),b,ISNUMBER(x),s,LEFT(x,2),IFS(
(l=18)*(s="1Z"),"UPS",
(l=12)*b,"FedEx",
(l=10)*b,"DHL",
(l=11)*(s="06"),"Old Dominion",
(l=9)*(s="00"),"Arcbest",
(l=10)*(s="00"),"Averitt"))
If nothing else it cuts down the formula length, and the function only takes one input cell reference (rather than 12 ...).
EDIT: Though if it were me (as other comments have mentioned) I would use this:
=LET(x,BM71,l,LEN(x),b,ISNUMBER(x),s,LEFT(x,2),c,IFS(
(l=18)*(s="1Z"),1,
(l=12)*b,2,
(l=10)*b,3,
(l=11)*(s="06"),4,
(l=9)*(s="00"),5,
(l=10)*(s="00"),6,
TRUE,7),INDEX(Carriers,c) )
With the range named Carriers holding the list of carriers, with a blank in the last row. Makes it easier to change a carrier name and you keep the list in one place which can be re-used by other formulas. (But then I am a devotee of the Third Normal Form ...)
You can add next one instead of "" of previous formula
=IF(AND(LEN(BM71)=18,LEFT(BM71,2)="1Z"), "UPS", IF(AND(LEN(BM71)=12,ISNUMBER(BM71)),"FedEx",IF(AND(LEN(BM71)=10,ISNUMBER(BM71)),"DHL",IF(AND(LEN(BM71)=11,LEFT(BM71,2)="06"), "Old Dominion", IF(AND(LEN(BM71)=9,LEFT(BM71,2)="00"), "Arcbest", IF(AND(LEN(BM71)=10,LEFT(BM71,2)="00"), "Averitt", ""))))))
However you approach to define something based on length and some chars is not stable
I hope I could help you

Regex to find numbers that are not in a phrase

If I have e.g. this string:
Beschreibung Menge VK-Preis MwSt% Betrag
Schadenbewertunginkl.Restwertermittlung 1 25,00€ 19 25,00€
Rechnungsbetragexcl.MwSt.: 25,00€
MwSt.(19%): 4,75€
Rechnungsbetragincl.MwSt.: 123.029,75€
I want to extract all the numbers.
My regexes are:
regex_up_to_thousand = r'\b(?:\d{1,3}){1}(?:,{1}\d{2})\b'
and
regex_every_price = r'\b(?:\d{1,3}(\.|,))+(:?\d{3}(\.|,))(?:\d{2})\b'
My idea was to first get the "big" prices, remove them from the text and get the other numbers.
Which works in most cases, until I have a date that looks like this maybe
Gutachtennummer: 1009126 Leistungsdatum: 11.10.2021
I would get the 11.10 with my second regex, and I don't know how to prevent this.
I thought the \b would help, but sadly not.
Any ideas?
It's not the end of the world, since I do a lot of math in the background, but it's a possibility that a date would fit some values and I calculate something wrong in the end.
You could try the following pattern.
\b\d+(?:(?:\.|,)\d{3})*(?:(?:\.|,)\d{2})\b(?!\W\d)
The main thing is (?!\W\d) at the end which ensures that after your amount you will not have a construct of 1 non-word character followed by 1 digit.
Example: https://regex101.com/r/q1ic9S/1

Excel formula to find two words after the prefix

I'm exporting a Jira issue into Excel to pull data from the description.
An example of the format would be:
"Author: Bob Bryant This is a test JIRA"
So that entire string occupies a single cell in Excel
I need to do an =IF(ISNUMBER(SEARCH("*Author*",Description)),"Author:","")
But instead of '"Author:"' I need it to take the 2 words after that (users full name), in this case I need it to take "Bob Bryant"
Unfortunately, Excel is not able to use regular expression (which would be much easier). You can workaround it with a temporary text substitution using SUBSTITUTE function.
With:
Prefix - the cell with the prefix, e.g. "Author:"
Description - the cell with original/source text
This is the formula you need is:
=IF(ISERR(SEARCH(Prefix;Description));"(no "&Prefix&" found)";IFERROR(TRIM(MID(Description;LEN(Prefix)+1;SEARCH("$$$";SUBSTITUTE(Description&" ";" ";"$$$";3))-LEN(Prefix)));"(too short)"))
Let's explain deeper:
=IF(
ISERR(SEARCH(Prefix;Description)); -- consider only cells with the right prefix (Author:)
"(no "&Prefix&" found)"; -- Prefix not found: return message
IFERROR( -- Prefix found: proceed
TRIM( -- remove any leading/trailing spaces
MID( -- return the text between prefix and 3rd space
Description;
LEN(Prefix)+1; -- start after the prefix
SEARCH( -- end before the substituted text ($$$)
"$$$";
SUBSTITUTE( -- substitute 3rd space (most important!)
Description&" "; -- add extra space (in case there's no other text after the name)
" ";
"$$$";
3))-LEN(Prefix)));"(too short)"))
Note, you might need to replace ; with , in your formula (depending on your system locales/regional settings).

Crystal Reports Formula Workshop boolean condition to string

I'm currently trying to create a report using Crystal Reports that comes with Visual Studio 2008.
I would like to include a field of type boolean on my report that shows a string rather than true or false. The string should contain either contain a € or a % sign.
How would I go about doing this in the Formula Workshop?
I've tried things like e.g.
if {tblAankoopDetails.SoortKorting} = true then "€" else "%"
However this never seems to work and results in warnings such as "The formula result must be a number".
This should be fairly simple but this is my first go at using Crystal Reports.
Help would be much appreciated.
Jay
Make sure your SoortKorting field has always true or false. Maybe there's a null and in that case your formula will not work.
Try with this:
if isnull({tblAankoopDetails.SoortKorting} ) then
" "
else
if {tblAankoopDetails.SoortKorting} =true
then "€" else "%"
Make sure there is nothing else in the same formula. Usually I see that particular error when a formula sometimes returns a string, and sometimes a number.
Also, you shouldn't need to test for true, so you might try:
if {tblAankoopDetails.SoortKorting} then "€" else "%"

How can I perform a reverse string search in Excel without using VBA?

I have an Excel spreadsheet containing a list of strings. Each string is made up of several words, but the number of words in each string is different.
Using built in Excel functions (no VBA), is there a way to isolate the last word in each string?
Examples:
Are you classified as human? -> human?
Negative, I am a meat popsicle -> popsicle
Aziz! Light! -> Light!
This one is tested and does work (based on Brad's original post):
=RIGHT(A1,LEN(A1)-FIND("|",SUBSTITUTE(A1," ","|",
LEN(A1)-LEN(SUBSTITUTE(A1," ","")))))
If your original strings could contain a pipe "|" character, then replace both in the above with some other character that won't appear in your source. (I suspect Brad's original was broken because an unprintable character was removed in the translation).
Bonus: How it works (from right to left):
LEN(A1)-LEN(SUBSTITUTE(A1," ","")) – Count of spaces in the original string
SUBSTITUTE(A1," ","|", ... ) – Replaces just the final space with a |
FIND("|", ... ) – Finds the absolute position of that replaced | (that was the final space)
Right(A1,LEN(A1) - ... )) – Returns all characters after that |
EDIT: to account for the case where the source text contains no spaces, add the following to the beginning of the formula:
=IF(ISERROR(FIND(" ",A1)),A1, ... )
making the entire formula now:
=IF(ISERROR(FIND(" ",A1)),A1, RIGHT(A1,LEN(A1) - FIND("|",
SUBSTITUTE(A1," ","|",LEN(A1)-LEN(SUBSTITUTE(A1," ",""))))))
Or you can use the =IF(COUNTIF(A1,"* *") syntax of the other version.
When the original string might contain a space at the last position add a trim function while counting all the spaces: Making the function the following:
=IF(ISERROR(FIND(" ",B2)),B2, RIGHT(B2,LEN(B2) - FIND("|",
SUBSTITUTE(B2," ","|",LEN(TRIM(B2))-LEN(SUBSTITUTE(B2," ",""))))))
This is the technique I've used with great success:
=TRIM(RIGHT(SUBSTITUTE(A1, " ", REPT(" ", 100)), 100))
To get the first word in a string, just change from RIGHT to LEFT
=TRIM(LEFT(SUBSTITUTE(A1, " ", REPT(" ", 100)), 100))
Also, replace A1 by the cell holding the text.
A more robust version of Jerry's answer:
=TRIM(RIGHT(SUBSTITUTE(TRIM(A1), " ", REPT(" ", LEN(TRIM(A1)))), LEN(TRIM(A1))))
That works regardless of the length of the string, leading or trailing spaces, or whatever else and it's still pretty short and simple.
I found this on google, tested in Excel 2003 & it works for me:
=IF(COUNTIF(A1,"* *"),RIGHT(A1,LEN(A1)-LOOKUP(LEN(A1),FIND(" ",A1,ROW(INDEX($A:$A,1,1):INDEX($A:$A,LEN(A1),1))))),A1)
[edit] I don't have enough rep to comment, so this seems the best place...BradC's answer also doesn't work with trailing spaces or empty cells...
[2nd edit] actually, it doesn't work for single words either...
=RIGHT(TRIM(A1),LEN(TRIM(A1))-FIND(CHAR(7),SUBSTITUTE(" "&TRIM(A1)," ",CHAR(7),
LEN(TRIM(A1))-LEN(SUBSTITUTE(" "&TRIM(A1)," ",""))+1))+1)
This is very robust--it works for sentences with no spaces, leading/trailing spaces, multiple spaces, multiple leading/trailing spaces... and I used char(7) for the delimiter rather than the vertical bar "|" just in case that is a desired text item.
This is very clean and compact, and works well.
{=RIGHT(A1,LEN(A1)-MAX(IF(MID(A1,ROW(1:999),1)=" ",ROW(1:999),0)))}
It does not error trap for no spaces or one word, but that's easy to add.
Edit:
This handles trailing spaces, single word, and empty cell scenarios. I have not found a way to break it.
{=RIGHT(TRIM(A1),LEN(TRIM(A1))-MAX(IF(MID(TRIM(A1),ROW($1:$999),1)=" ",ROW($1:$999),0)))}
=RIGHT(A1,LEN(A1)-FIND("`*`",SUBSTITUTE(A1," ","`*`",LEN(A1)-LEN(SUBSTITUTE(A1," ","")))))
New answer 9/28/2022
Considering the new excel function: TEXTAFTER (check availability) you can achieve it with a simple formula:
=TEXTAFTER(A1," ", -1)
To add to Jerry and Joe's answers, if you're wanting to find the text BEFORE the last word you can use:
=TRIM(LEFT(SUBSTITUTE(TRIM(A1), " ", REPT(" ", LEN(TRIM(A1)))), LEN(SUBSTITUTE(TRIM(A1), " ", REPT(" ", LEN(TRIM(A1)))))-LEN(TRIM(A1))))
With 'My little cat' in A1 would result in 'My little' (where Joe and Jerry's would give 'cat'
In the same way that Jerry and Joe isolate the last word, this then just gets everything to the left of that (then trims it back)
Copy into a column, select that column and HOME > Editing > Find & Select, Replace:
Replace All.
There is a space after the asterisk.
Imagine the string could be reversed. Then it is really easy. Instead of working on the string:
"My little cat" (1)
you work with
"tac elttil yM" (2)
With =LEFT(A1;FIND(" ";A1)-1) in A2 you get "My" with (1) and "tac" with (2), which is reversed "cat", the last word in (1).
There are a few VBAs around to reverse a string. I prefer the public VBA function ReverseString.
Install the above as described. Then with your string in A1, e.g., "My little cat" and this function in A2:
=ReverseString(LEFT(ReverseString(A1);IF(ISERROR(FIND(" ";A1));
LEN(A1);(FIND(" ";ReverseString(A1))-1))))
you'll see "cat" in A2.
The method above assumes that words are separated by blanks. The IF clause is for cells containing single words = no blanks in cell. Note: TRIM and CLEAN the original string are useful as well. In principle it reverses the whole string from A1 and simply finds the first blank in the reversed string which is next to the last (reversed) word (i.e., "tac "). LEFT picks this word and another string reversal reconstitutes the original order of the word (" cat"). The -1 at the end of the FIND statement removes the blank.
The idea is that it is easy to extract the first(!) word in a string with LEFT and FINDing the first blank. However, for the last(!) word the RIGHT function is the wrong choice when you try to do that because unfortunately FIND does not have a flag for the direction you want to analyse your string.
Therefore the whole string is simply reversed. LEFT and FIND work as normal but the extracted string is reversed. But his is no big deal once you know how to reverse a string. The first ReverseString statement in the formula does this job.
=LEFT(A1,FIND(IF(
ISERROR(
FIND("_",A1)
),A1,RIGHT(A1,
LEN(A1)-FIND("~",
SUBSTITUTE(A1,"_","~",
LEN(A1)-LEN(SUBSTITUTE(A1,"_",""))
)
)
)
),A1,1)-2)
I translated to PT-BR, as I needed this as well.
(Please note that I've changed the space to \ because I needed the filename only of path strings.)
=SE(ÉERRO(PROCURAR("\",A1)),A1,DIREITA(A1,NÚM.CARACT(A1)-PROCURAR("|", SUBSTITUIR(A1,"\","|",NÚM.CARACT(A1)-NÚM.CARACT(SUBSTITUIR(A1,"\",""))))))
Another way to achieve this is as below
=IF(ISERROR(TRIM(MID(TRIM(D14),SEARCH("|",SUBSTITUTE(TRIM(D14)," ","|",LEN(TRIM(D14))-LEN(SUBSTITUTE(TRIM(D14)," ","")))),LEN(TRIM(D14))))),TRIM(D14),TRIM(MID(TRIM(D14),SEARCH("|",SUBSTITUTE(TRIM(D14)," ","|",LEN(TRIM(D14))-LEN(SUBSTITUTE(TRIM(D14)," ","")))),LEN(TRIM(D14)))))
You can achieve this also by reversing the string and finding the first space
=MID(C3,2+LEN(C3)-SEARCH(" ",CONCAT(MID(C3,SEQUENCE(LEN(C3),,LEN(C3),-1),1))),LEN(A1))
Reverse the string
CONCAT(MID(C3,SEQUENCE(LEN(C3),,LEN(C3),-1),1))
Find the first space in the reversed string
SEARCH(" ",...
Take the position of the space found in the reversed string off the length of the string and return that portion
=MID(C3,2+LEN(C3)-SEARCH...
I also had a task like this and when I was done, using the above method, a new method occured to me: Why don't you do this:
Reverse the string ("string one" becomes "eno gnirts").
Use the good old Find (which is hardcoded for left-to-right).
Reverse it into readable string again.
How does this sound?

Resources