Equation to remove last character if letter and first leading 0

NormChart55

New Member
Joined
Feb 22, 2022
Messages
44
Office Version
  1. 2016
Platform
  1. Windows
Hello,

I am looking for a way to remove letters if they appear at the end of an item as well as removing a 0 only if it appears between 000 and 099 after the characters "RV". I have an example list below and hoping there is an easy way to remove these from a mass list with a formula. Thanks for any information and help.

Examples
Store numbers - always starts with RV and could go up to RV9999a (or b,c,d,e)

RV002A - should be RV02
RV050G - should be RV50
RV027H - should be RV27
RV1000 - should be RV1000
RV429A - should be RV429
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Will there ever only be one single letter at the end, or could there be more than one?
 
Upvote 0
If there will never be more than one letter at the end of the entry, then try this formula (for an entry in cell A1):
Excel Formula:
=LEFT(A1,2) & IFERROR(MID(A1,3,LEN(A1)-2)+0,MID(A1,3,LEN(A1)-3)+0)
 
Upvote 0
Another way using VBA.

NORM55
BC
1RV002ARV02
2RV050GRV50
3RV027HRV27
4RV1000RV1000
5RV429ARV429
Sheet5
Cell Formulas
RangeFormula
C1:C5C1=NORM55(B1)


VBA Code:
Function NORM55(s As String)
With CreateObject("VBScript.RegExp")
    .Pattern = "(RV)(\d+)"
    Set matches = .Execute(s)(0).submatches
    NORM55 = matches(0) & _
    Format(Int(matches(1)), "00")
End With
End Function
 
Upvote 0
how about:
mr excel questions 20.xlsm
AB
1RV002ARV02
2RV050GRV50
3RV027HRV27
4RV1000RV1000
5RV429ARV429
Sheet5
Cell Formulas
RangeFormula
B1:B5B1=SUBSTITUTE(IF(ISNUMBER(VALUE(RIGHT(A1,1))),A1,LEFT(A1,LEN(A1)-1)),"RV0","RV",1)
 
Upvote 0
If there will never be more than one letter at the end of the entry, then try this formula (for an entry in cell A1):
Excel Formula:
=LEFT(A1,2) & IFERROR(MID(A1,3,LEN(A1)-2)+0,MID(A1,3,LEN(A1)-3)+0)

Thanks for the information. There is only ever 1 letter. I applied this one, but I am getting the stores that are between 1-10 do not have a 0.

Example: WZ002A -> goes to WZ2 but should be WZ02. All others are coming out as expected
 
Upvote 0
Another option
Excel Formula:
=REPLACE(LEFT(A2,LEN(A2)-ISERR(RIGHT(A2)+0)),3,MID(A2,3,1)="0","")
 
Upvote 0
Solution
Another way using VBA.

NORM55
BC
1RV002ARV02
2RV050GRV50
3RV027HRV27
4RV1000RV1000
5RV429ARV429
Sheet5
Cell Formulas
RangeFormula
C1:C5C1=NORM55(B1)


VBA Code:
Function NORM55(s As String)
With CreateObject("VBScript.RegExp")
    .Pattern = "(RV)(\d+)"
    Set matches = .Execute(s)(0).submatches
    NORM55 = matches(0) & _
    Format(Int(matches(1)), "00")
End With
End Function

Thanks for the information. I tried this one, I added a module with the attached VBA and applied that formula but its giving me a #VALUE?
 
Upvote 0
Another option
Excel Formula:
=REPLACE(LEFT(A2,LEN(A2)-ISERR(RIGHT(A2)+0)),3,MID(A2,3,1)="0","")

Thank you for the information. This one did exactly as I expected/wanted. Very much appreciated, you guys amaze me. thanks all for the help!
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,636
Latest member
laura12345

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