Need help with a function to Find and Replace

bbenny01

New Member
Joined
Jun 5, 2020
Messages
5
Office Version
  1. 2010
Platform
  1. Windows
  2. MacOS
Hello, I would like to know if there is a function that can find multiple shorten year ranges in a cell and replace it with the full year range.

Example of shorten year range:
Buick LaCrosse 16-14, Regal 17-14
Mazda 18-14 3, 18-14 3 Sport
Hyundai 17-16 Tucson, Kia: 17 Sportage

Updated to Full year range
LaCrosse 2016-2014, Regal 2017-2014
Mazda 2018-2014 3, 2018-2014 3 Sport
Hyundai 2017-2016 Tucson, Kia: 2017 Sportage

I did try using the SUBSTITUTE function with a wildcard but it did not work.
Here is an example function I used for Buick LaCrosse 16-14, Regal 17-14 is in cell A1:
=SUBSTITUTE(A1,"1*-1*","201*-201*")
It returned the same exact data: LaCrosse 16-14, Regal 17-14

Your help will be greatly appreciated!
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Hi & welcome to MrExcel.
Unfortunately you cannot use wildcards in substitute.
This will do the date ranges in your example, but not the solo years.

+Fluff New.xlsm
AB
1
2Buick LaCrosse 16-14, Regal 17-14Buick LaCrosse 2016-2014, Regal 2017-2014
3Mazda 18-14 3, 18-14 3 SportMazda 2018-2014 3, 2018-2014 3 Sport
4Hyundai 17-16 Tucson, Kia: 17 SportageHyundai 2017-2016 Tucson, Kia: 17 Sportage
Lookup
Cell Formulas
RangeFormula
B2:B4B2=SUBSTITUTE(REPLACE(IFERROR(REPLACE(A2,FIND("-",A2,FIND("-",A2&"-")+1)-2,0,20),A2),FIND("-",A2)-2,0,20),"-","-20")
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0
Hi Fluff, the function works for cells with 2 beginning years.

Example below

=SUBSTITUTE(REPLACE(IFERROR(REPLACE(G48,FIND("-",G48,FIND("-",G48&"-")+1)-2,0,20),G48),FIND("-",G48)-2,0,20),"-","-20")

GLK250 15-13, GLK350 15-10

will convert to

GLK250 2015-2013, GLK350 2015-2010

If the same function is applied to the line below - This has about 18 year ranges

535i GT 16-10, 535i GT xDrive 16-11, 550i 16-11, 550i GT 15-11, 550i GT xDrive 15-11, 550i xDrive 15-11, 650i 16-12, 650i Gran Coupe 16-13, 650i xDrive 16-12, 650i xDrive Gran Coupe 16-13, 740i 15-11, 740Ld xDrive 15, 740Li 15-11, 740Li xDrive 15-13, 750i 15-09, 750i xDrive 15-10, 750Li 15-09, 750Li xDrive 15-10, ActiveHybrid 7 15-13

It only converts up to the 2nd beginning year.

535i GT 2016-2010, 535i GT xDrive 2016-2011, 550i 16-2011, 550i GT 15-2011, 550i GT xDrive 15-2011, 550i xDrive 15-2011, 650i 16-2012, 650i Gran Coupe 16-2013, 650i xDrive 16-2012, 650i xDrive Gran Coupe 16-2013, 740i 15-2011, 740Ld xDrive 15, 740Li 15-2011, 740Li xDrive 15-2013, 750i 15-2009, 750i xDrive 15-2010, 750Li 15-2009, 750Li xDrive 15-2010, ActiveHybrid 7 15-2013

There are some year ranges I'm working with that go up to 35+

Hope this makes sense....
 
Upvote 0
Forgot to mention the function does convert the ending years...
 
Upvote 0
Ok, in that case I think you really need a UDF.
VBA Code:
Function bbenny(Txt As String) As String
   Dim Sp As Variant
   Dim i As Long
  
   Sp = Split(Txt)
   For i = 0 To UBound(Sp)
      If InStr(1, Sp(i), "-") > 0 Then
         Sp(i) = "20" & Left(Sp(i), 2) & "-20" & Mid(Sp(i), 4)
      End If
   Next i
   bbenny = Join(Sp, " ")
End Function

+Fluff New.xlsm
AB
1
2Buick LaCrosse 16-14, Regal 17-14Buick LaCrosse 2016-2014, Regal 2017-2014
3Mazda 18-14 3, 18-14 3 SportMazda 2018-2014 3, 2018-2014 3 Sport
4Hyundai 17-16 Tucson, Kia: 17 SportageHyundai 2017-2016 Tucson, Kia: 17 Sportage
5535i GT 16-10, 535i GT xDrive 16-11, 550i 16-11, 550i GT 15-11, 550i GT xDrive 15-11, 550i xDrive 15-11, 650i 16-12, 650i Gran Coupe 16-13, 650i xDrive 16-12, 650i xDrive Gran Coupe 16-13, 740i 15-11, 740Ld xDrive 15, 740Li 15-11, 740Li xDrive 15-13, 750i 15-09, 750i xDrive 15-10, 750Li 15-09, 750Li xDrive 15-10, ActiveHybrid 7 15-13535i GT 2016-2010, 535i GT xDrive 2016-2011, 550i 2016-2011, 550i GT 2015-2011, 550i GT xDrive 2015-2011, 550i xDrive 2015-2011, 650i 2016-2012, 650i Gran Coupe 2016-2013, 650i xDrive 2016-2012, 650i xDrive Gran Coupe 2016-2013, 740i 2015-2011, 740Ld xDrive 15, 740Li 2015-2011, 740Li xDrive 2015-2013, 750i 2015-2009, 750i xDrive 2015-2010, 750Li 2015-2009, 750Li xDrive 2015-2010, ActiveHybrid 7 2015-2013
Lookup
Cell Formulas
RangeFormula
B2:B5B2=bbenny(A2)
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,790
Messages
6,121,607
Members
449,037
Latest member
Arbind kumar

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