Ajusting number based on test

Rbartlem

Board Regular
Joined
Jun 9, 2004
Messages
172
I have 2 columns. in column 1 I have information with how long I purchased/renewed a domain. I need column b to show just the # of years that are in column a. So b1 would have 1, b2 would have 2, b3 would have 1, b4 would have 2. Anyone have an idea of how to do this with a macro or a formula? Preferrably a formula if possible.

example:

Code:
             A                     B  
.com renewal 1 year       |                      | 
.com renewal 2 years      |                      | 
.net registration         |                      | 
.net registration 2 years |                      |

The acctual data looks like this ".COM Domain Name Renewal - 1 Year" but some only look like this... "Other Type Of Services". I tried to make this formula =RIGHT(A2,LEN(A2)-FIND("- ",A2)-1) which is leaving "1 Year" and I just need it to say "1" I also need it to just show a 1 instead of #VALUE! on other types.
 
Try...

=TRIM(MID(A2,FIND("^^",SUBSTITUTE(A2,"-","^^",LEN(A2)-LEN(SUBSTITUTE(A2,"-",""))))+1,SEARCH("year",A2)-FIND("^^",SUBSTITUTE(A2,"-","^^",LEN(A2)-LEN(SUBSTITUTE(A2,"-",""))))-1))
..which will extract characters between the last hyphen and the word 'year'.

Hope this helps!
 
Upvote 0

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
I tried using your code on "Bulk Domain Name Registration (6-20) - 2 years" and it didn't work...

I used the below code and it worked perfect. I thought that the (1-1) had a hyphen in it but it didn't. I just needed to change it to search for a hyphen with a space and problem solved. Thank you very much!

Code:
=IF(A1>0,IF(ISERROR(MID(B1,SEARCH("- ",B1)+1,(SEARCH("Year",B1)-1)-SEARCH("- ",B1))+0),1,(MID(B1,SEARCH("- ",B1)+1,(SEARCH("Year",B1)-1)-SEARCH("- ",B1))+0)),"")
 
Upvote 0
I just tried my formula and it returns the number 2. What do you get?
 
Upvote 0

Forum statistics

Threads
1,215,659
Messages
6,126,077
Members
449,286
Latest member
Lantern

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