How to specify an empty space in search/find functions?

cotatliad

New Member
Joined
Jul 6, 2011
Messages
19
I am trying to use the Find/Search functions to determine where the empty space ends and where the actual characters begin. So for example "___Room" would have 3 spaces before actual characters (_ represents empty space, assume there is nothing there). How do I make search/find distinguish between empty space and characters? Thanks!!
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
There are seveal ways. if you only have leading spaces at the beginning, and no trailing spaces at the end you can use the following function:

=LEN(A1)-LEN(TRIM(A1))+1

This tells you that the first non space is in the 9th spot.

You can also use a User Defined Function with the following syntax:

=GoodChar(A1)

And this is the code you'd need to use.

Code:
Function GoodChar(cl As Range) As Long
If cl.Rows.Count > 1 And cl.Columns.Count > 1 Then
    GoodChar = -1
Else
    GoodChar = 1
    Do Until Mid(cl, GoodChar, 1) <> " "
        GoodChar = GoodChar + 1
    Loop
End If
End Function
 
Upvote 0
Hi cotatliad,

An option with sheet formula.
Excel Workbook
ABC
1Room3End of space character
24Begin of first letter or number
...
Cell Formulas
RangeFormula
B1=LEN(A1)-LEN(SUBSTITUTE(A1," ",""))
B2=LEN(A1)-LEN(SUBSTITUTE(A1," ",""))+1


Regards.
 
Upvote 0

Forum statistics

Threads
1,224,595
Messages
6,179,798
Members
452,943
Latest member
Newbie4296

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