All characters left of a number

swaink

Active Member
Joined
Feb 15, 2002
Messages
432
Hi All

I wonder if you can assist me please

I am in the process of cleaning up some date (1.5m records) its a slow process but i'm getting there

However I have become stuck on a query for one field, the field should only contain names but in some instances I am seeing address details too

I have been running update queries to tidy up but I am not stuck as to how I can look foir all the characters to the left of a number

for example Mr Jon Do 43 terrace gardens I only want to see Mr Jon Do

I have tried this Expr1: Left([contact],(InStr(1,[contact],'1')-1)) but I wondered if there is anyway to get the left of any numeric value rather than do this one at a time

Any advice appreciated

All the best

Kevin
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Hi Kevin,

Give this a try:

=LEFT(A1,MIN(IFERROR(FIND(B1:B10,A1),""))-2)

This is an array formula, enter with CTRL + SHIFT + ENTER.

A1 is the cell with the text.
The range B1:B10 has the list of numbers from 0-9.

Let me know if you get stuck

Thanks,
Dan
 
Upvote 0
Hi Dan

Thank you for the reply mate I do appreciate it

Unfortunately this works ok in Excel but I need to do the same sort of thing but in Access and thats where I am stuck

All the best

Kevin
 
Upvote 0
One way is to create a User Defined Function like this:
Code:
Function GetText(myEntry As Variant) As String


    Dim myLen As Long
    Dim i As Long
    
    myLen = Len(Nz(myEntry, ""))
    If myLen > 0 Then
        For i = 1 To myLen
            If IsNumeric(Mid(myEntry, i, 1)) Then
                Exit For
            End If
        Next i
        GetText = Trim(Left(myEntry, i - 1))
    Else
        GetText = ""
    End If
    
End Function
Then, just use it like any other Function in a calculated field, i.e.
NameOnly: GetText([contact])
 
Upvote 0
Ahhh sorry Kevin!

I was using the 'Zero Reply Posts' section and didn't notice the forum...

Hope Joe's solution works!!
 
Upvote 0
I was using the 'Zero Reply Posts' section and didn't notice the forum...
You be surprised how often that happens! I have seen three in the last week.

Since the forum is listed over to the right, it can be easy to miss.
 
Upvote 0
Hi Guys

Thank you for your help

Joe this work great for me and will save a lot of time going forward

Dan no worries mate I had to double check I had posted it in the right forum as I don't usually use Access so still learning

Appreciated Joe thanks again

Kevin
 
Upvote 0
Your welcome!
Glad to help!
:)
 
Upvote 0
Hi Joe

Just out of interest should I ever need it how could the function be tweaked to to get everything to the right of and including the number i,e, 43 terrace gardens

All the best

Kevin
 
Upvote 0
swaink,

Why not try taking a stab at it? It will be a good test to see if you understand what the code is doing.
Once you see how it works, it should be pretty easy to make that modification.
Note, this is the line you most want to focus on:
Code:
GetText = Trim(Left(myEntry, i - 1))

See how you do and post back!
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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