I have excel file like this
983 David
75Harshan
0 vivek
I want to remove 983 from excel cell 1, remove 75 from second cell, remove 0 from third cell. How this possible? ie. I want to remove all the prefixing digits from an excel cell.
I have excel file like this
983 David
75Harshan
0 vivek
I want to remove 983 from excel cell 1, remove 75 from second cell, remove 0 from third cell. How this possible? ie. I want to remove all the prefixing digits from an excel cell.
This formula will retain all of the string in A1 except any leading numeric characters. Copy down as required.
=MID(A1,MATCH(TRUE,ISERROR(VALUE(MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1))),0),LEN(A1))
The formula works as is on Excel 365. For earlier versions of Excel you may have to enter it as an array formula (confirm with Ctl+Shift+Enter)
For any version of Excel that supports VBA, consider the following User Defined Function:
Option Explicit
Public Function NoDig(s As String) As String
Dim i As Long, L As Long, CH As String
NoDig = s
L = Len(s)
For i = 1 To L
CH = Left(NoDig, 1)
If CH Like "[0-9]" Then
NoDig = Mid(NoDig, 2, 9999)
Else
Exit Function
End If
Next i
End Function
User Defined Functions (UDFs) are very easy to install and use:
If you save the workbook, the UDF will be saved with it. If you are using a version of Excel later then 2003, you must save the file as .xlsm rather than .xlsx
To remove the UDF:
To use the UDF from Excel:
=myfunction(A1)
To learn more about macros in general, see:
http://www.mvps.org/dmcritchie/excel/getstarted.htm
and
http://msdn.microsoft.com/en-us/library/ee814735(v=office.14).aspx
and for specifics on UDFs, see:
http://www.cpearson.com/excel/WritingFunctionsInVBA.aspx
Macros must be enabled for this to work!
You could use an array formula like
=IF(A2="","",RIGHT(A2,LEN(A2)-MAX(IF(((CODE(MID(A2,SEQUENCE(LEN(A2)),1))<48)+(CODE(MID(A2,SEQUENCE(LEN(A2)),1))>57)),0,SEQUENCE(LEN(A2))))))
or (more fun) a Lambda RemoveDigits(s) if you have it
=LAMBDA(s,IF(s="","",IF(OR(CODE(LEFT(s))<48,CODE(LEFT(s))>57),s,RemoveDigits(RIGHT(s,LEN(s)-1)))))
Note that these give different results in the last example:
I've replaced the first formula with something more or less equivalent to the lambda.