Verifying 5th character from the end of text string by searching from right to left

Pneumafire

New Member
Joined
Apr 17, 2013
Messages
4
I am using Excel 2010.

I have text strings between 30 and 40 characters in length. Let's say I have a 40-character text string in a cell, with the last 6 characters being 7 1210

What I need to do is to verify if the character between the 7 and the 1 is a space.

The formula that I need would be the equivalent of "If the fifth character from the right = " ", then do this..."

I don't want to search from the left unless I have to because there are at least 5 spaces in every string, but I am only interested in the fifth character from the end of the string. If it is a space, then I will take one action; if it is not, then I will take another.

Thanks in advance to you pros that can solve tough puzzles like this one!
 

Some videos you may like

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

mikerickson

MrExcel MVP
Joined
Jan 15, 2007
Messages
23,916
You use a formula like this
=CODE(RIGHT(A1,5))=CODE(" ")

or (less genric)
=CODE(RIGHT(A1,5))=32
 

Pneumafire

New Member
Joined
Apr 17, 2013
Messages
4
Perfect! Well done, Mike. Thanks for the quick reply, and thanks for two solutions - they both work beautifully and accomplish exactly what I needed. Again, big KUDOS to you.
 

Pneumafire

New Member
Joined
Apr 17, 2013
Messages
4
Mike, FYI, Excel 2010 likes CODE 160 (which is also a blank space) over 32, at least with the default font Calibri.
 

L. Howard

Well-known Member
Joined
Oct 16, 2012
Messages
4,514
Here's another, bit longer tho.

=IF(--RIGHT(F1,4)=--RIGHT(F1,5),"Space","No Space")

Regards,
Howard
 

Watch MrExcel Video

Forum statistics

Threads
1,123,057
Messages
5,599,550
Members
414,316
Latest member
ExcelLee

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
Top