Formula to extract first character from right side but before the numeric data

mehidy1437

Active Member
Joined
Nov 15, 2019
Messages
348
Office Version
  1. 365
  2. 2016
  3. 2013
Platform
  1. Windows
  2. Mobile
  3. Web
Hi guys,

I want the below result from the string, how can I do this with formula?

Book1
AB
1STRINGREQUIRED RESULT
2BBBA123A
3BB1234B
4CC3C
5DD123CD
6F11CCD32CD
7F11CCE32CME
8F11CCF3CMF
9F11CCG345CG
Sheet1
Capture.PNG
 
Here is another array-entered** formula (it is non-Volatile) that you can try...
Excel Formula:
=MID(A2,MAX(IF(ISNUMBER(-MID(A2,ROW($1:$1000),1)),ROW($1:$1000)))-LEN(RIGHT(LEFT(A2,MAX(IF(ISNUMBER(-MID(A2,ROW($1:$1000),1)),ROW($1:$1000)))),COUNT(,-RIGHT(LEFT(A2,MAX(IF(ISNUMBER(-MID(A2,ROW($1:$1000),1)),ROW($1:$1000)))),ROW($1:$15)))-1)),1)
**Commit this formula using CTRL+SHIFT+ENTER and not just Enter by itself
 
Upvote 0

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Here is another array-entered** formula (it is non-Volatile) that you can try...
Excel Formula:
=MID(A2,MAX(IF(ISNUMBER(-MID(A2,ROW($1:$1000),1)),ROW($1:$1000)))-LEN(RIGHT(LEFT(A2,MAX(IF(ISNUMBER(-MID(A2,ROW($1:$1000),1)),ROW($1:$1000)))),COUNT(,-RIGHT(LEFT(A2,MAX(IF(ISNUMBER(-MID(A2,ROW($1:$1000),1)),ROW($1:$1000)))),ROW($1:$15)))-1)),1)
**Commit this formula using CTRL+SHIFT+ENTER and not just Enter by itself
Thanks, Rick.
Is it possible to do without CSE?
 
Upvote 0
Could use VBA.

Book1
ABC
1STRINGREQUIRED RESULTCustom Function
2BBBA123AA
3BB1234BB
4CC3CC
5DD123CDD
6F11CCD32CDD
7F11CCE32CMEE
8F11CCF3CMFF
9F11CCG345CGG
Sheet1
Cell Formulas
RangeFormula
C2:C9C2=fc(A2)


VBA Code:
Function FC(s As String)
Dim bt() As Byte: bt = s
Dim b As Boolean: b = False

For i = UBound(bt) - 1 To 0 Step -2
    If bt(i) > 47 And bt(i) < 58 Then
        b = True
    End If
   
    If bt(i) > 64 And bt(i) < 91 And b Then
        FC = Chr(bt(i))
        Exit Function
    End If
Next i
End Function
Hi dear, how can grab two characters with this function?
 
Upvote 0
Hi dear, how can grab two characters with this function?
I know you posted this question against a UDF (user defined function) posting, but you can use a slight modification to the array-entered** formula I posted earlier to get the 2 characters before the last number...
Excel Formula:
=MID(A2,MAX(IF(ISNUMBER(-MID(A2,ROW($1:$1000),1)),ROW($1:$1000)))-LEN(RIGHT(LEFT(A2,MAX(IF(ISNUMBER(-MID(A2,ROW($1:$1000),1)),ROW($1:$1000)))),COUNT(,-RIGHT(LEFT(A2,MAX(IF(ISNUMBER(-MID(A2,ROW($1:$1000),1)),ROW($1:$1000)))),ROW($1:$15))))),2)
** Commit this formula using CTRL+SHIFT+ENTER and not just Enter by itself
.
 
Upvote 0
Hi dear, how can grab two characters with this function?
Besides the formula solution I just gave you immediately above in Message #16, here is a UDF (user defined function) that will retrieve as many characters before the last number as you specify...
VBA Code:
Function GetCharsBeforeLastNum(ByVal S As String, HowMany As Long) As String
  Dim X As Long, Arr() As String
  S = S & "Z"
  For X = 1 To Len(S)
    If Mid(S, X, 1) Like "#" Then Mid(S, X) = " "
  Next
  Arr = Split(Application.Trim(S))
  GetCharsBeforeLastNum = Right(Arr(UBound(Arr) - 1), HowMany)
End Function
To use the function, simply pass in a text string or cell reference to a text string as the first argument and the number of characters to retrieve as the second argument. For example...
Excel Formula:
=GetCharsBeforeLastNum(A1,2)
 
Upvote 0
Besides the formula solution I just gave you immediately above in Message #16, here is a UDF (user defined function) that will retrieve as many characters before the last number as you specify...
VBA Code:
Function GetCharsBeforeLastNum(ByVal S As String, HowMany As Long) As String
  Dim X As Long, Arr() As String
  S = S & "Z"
  For X = 1 To Len(S)
    If Mid(S, X, 1) Like "#" Then Mid(S, X) = " "
  Next
  Arr = Split(Application.Trim(S))
  GetCharsBeforeLastNum = Right(Arr(UBound(Arr) - 1), HowMany)
End Function
To use the function, simply pass in a text string or cell reference to a text string as the first argument and the number of characters to retrieve as the second argument. For example...
Excel Formula:
=GetCharsBeforeLastNum(A1,2)
Thanks a lot dear.
 
Upvote 0
I know you posted this question against a UDF (user defined function) posting, but you can use a slight modification to the array-entered** formula I posted earlier to get the 2 characters before the last number...
Excel Formula:
=MID(A2,MAX(IF(ISNUMBER(-MID(A2,ROW($1:$1000),1)),ROW($1:$1000)))-LEN(RIGHT(LEFT(A2,MAX(IF(ISNUMBER(-MID(A2,ROW($1:$1000),1)),ROW($1:$1000)))),COUNT(,-RIGHT(LEFT(A2,MAX(IF(ISNUMBER(-MID(A2,ROW($1:$1000),1)),ROW($1:$1000)))),ROW($1:$15))))),2)
** Commit this formula using CTRL+SHIFT+ENTER and not just Enter by itself
.
Please help me to understand, what is ROW($1:$1000) & ROW($1:$15) doing here?
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,244
Members
452,622
Latest member
Laura_PinksBTHFT

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