# Ajusting number based on test

#### Rbartlem

##### Board Regular
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

If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.

#### Rbartlem

##### Board Regular
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?

#### Domenic

##### MrExcel MVP
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!

#### Rbartlem

##### Board Regular
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))``

#### Domenic

##### MrExcel MVP

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

Hope this helps!

#### Rbartlem

##### Board Regular
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?

#### Domenic

##### MrExcel MVP

Use SEARCH instead. It's not case sensitive. So, for example, change...

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

to

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

Hope this helps!

#### Rbartlem

##### Board Regular
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...

#### Domenic

##### MrExcel MVP
I just tried the formula and it returns 2. What do you get?

#### Rbartlem

##### Board Regular
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...

Replies
0
Views
48
Replies
3
Views
180
Replies
1
Views
94
Replies
9
Views
168
Replies
2
Views
112