Hi,
I would like a macro to find the postition of the last number in a string. E.g. for "hello2021today" it should give 9.
Any ideas?
Hi,
I would like a macro to find the postition of the last number in a string. E.g. for "hello2021today" it should give 9.
Any ideas?
Simple UDF.
Use in cell like
=FindLastDigit(A1)
Function FindLastDegit(ByVal txt As String) As Long Dim i As Long For i = Len(txt) To 1 Step -1 If Mid$(txt, i, 1) Like "[0-9]" Then FindLastDegits = i: Exit For Next End Function
You say you want a macro, but it sounds more like you would want a UDF (user defined function), so that is what I am giving you (you can convert this easily enough into a macro if that is really what you want)...
Function LastDigitPosition(S As String) As Long For LastDigitPosition = Len(S) To 1 Step -1 If Mid(S, LastDigitPosition, 1) Like "#" Then Exit For Next End Function
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks