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.
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
What I have so far...

This is what I have so far...

Code:
=IF(ISERROR(RIGHT(a2,LEN(a2)-FIND("- ",a2)-1)),1,(RIGHT(a2,LEN(a2)-FIND("- ",a2)-1)))

It is leaving either the #1 if there is an error which is perfect, but when it seperates the years it says "1 Year" or "2 Years", where I just need a 1 or a 2 or 5 or whatever. Anyone have any ideas?
 
Upvote 0
If each text string contains both a dash and the word 'year', try...

=MID(A2,FIND("-",A2)+1,(FIND("year",A2)-1)-FIND("-",A2))+0

To return 0 when no number is present, try the following instead...

=LOOKUP(9.99999999999999E+307,CHOOSE({1,2},0,MID(A2,FIND("-",A2)+1,(FIND("year",A2)-1)-FIND("-",A2))+0))

Hope this helps!
 
Upvote 0
Excelletn

I modified that slightly to make the following... I'm sure there is a more eficcient way of doing it, but it works for me!

Code:
=IF(ISERROR(MID(C2,FIND("-",C2)+1,(FIND("Year",C2)-1)-FIND("-",C2))+0),1,(MID(C2,FIND("-",C2)+1,(FIND("Year",C2)-1)-FIND("-",C2))+0))
 
Upvote 0
How about...

=IF(ISNUMBER(FIND("-",C2)),MID(C2,FIND("-",C2)+1,(FIND("year",C2)-1)-FIND("-",C2))+0,1)

Hope this helps!
 
Upvote 0
OK so I thought everything was working, except that sometimes year is lower case, and sometimes the Y is uppercase... Is there a way to make it always work?
 
Upvote 0
Use SEARCH instead. It's not case sensitive. So, for example, change...

(FIND("year",C2)-1)

to

(SEARCH("year",C2)-1)

Hope this helps!
 
Upvote 0
Ok another problem. Some of the cells contain data that looks like this: ".COM Registration (500) - 2 years" and for some reason it doesn't work on those cells...
 
Upvote 0
I just tried the formula and it returns 2. What do you get?
 
Upvote 0
I'm sorry that was messed up. It says ".com registration bulk (250 - 500) - 1 year" so the first hyphen is throwing it all off...
 
Upvote 0

Forum statistics

Threads
1,213,485
Messages
6,113,931
Members
448,533
Latest member
thietbibeboiwasaco

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