Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
David
 
Posts: n/a
Default Converting text to numbers

How do I convert say 1m5f109y into yards where "m" =
1*1760 "f" = 5*220 and "y" = 109, which is 2969 yards in
total.I thought of a Lookup Table but that would involve
hundreds of lines.The distances would vary from 5f the
lowest to 2m7f219y the highest.Any help would be
appreciated.

  #2   Report Post  
Trevor Shuttleworth
 
Posts: n/a
Default

David

one way:

=(--LEFT(A1,FIND("m",A1)-1)*1760) +
(--MID(A1,FIND("m",A1)+1,FIND("f",A1)-FIND("m",A1)-1)*220) +
(--MID(A1,FIND("f",A1)+1,FIND("y",A1)-FIND("f",A1)-1))

2m7f219y = 5279

You would need to enter the data in the format aaambfcccy otherwise the
find(s) will fail and you'd get #VALUE! You could maybe put some error
checking in as a fail safe but it would be easier to enter 2m0f22y without
error checking than 2m22y with error checking

Regards

Trevor



"David" wrote in message
...
How do I convert say 1m5f109y into yards where "m" =
1*1760 "f" = 5*220 and "y" = 109, which is 2969 yards in
total.I thought of a Lookup Table but that would involve
hundreds of lines.The distances would vary from 5f the
lowest to 2m7f219y the highest.Any help would be
appreciated.



  #3   Report Post  
Dave Peterson
 
Posts: n/a
Default

I'd use a userdefined function:

Option Explicit
Function myConversion(myStr As String) As Variant

Dim res As Variant

myStr = LCase(myStr)
myStr = Application.Substitute(myStr, "m", "*1760+")
myStr = Application.Substitute(myStr, "f", "*220+")
myStr = Application.Substitute(myStr, "y", "")

If Right(myStr, 1) = "+" Then
myStr = Left(myStr, Len(myStr) - 1)
End If

res = Application.Evaluate(myStr)

If IsError(res) Then
myConversion = "Format Error"
Else
myConversion = res
End If

End Function

==========
If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Short course:

Open your workbook.
Hit alt-f11 to get to the VBE (where macros/UDF's live)
hit ctrl-R to view the project explorer
Find your workbook.
should look like: VBAProject (yourfilename.xls)

right click on the project name
Insert, then Module
You should see the code window pop up on the right hand side

Paste the code in there.

Now go back to excel.
Into a test cell and type:
=myconversion(a1)

David wrote:

How do I convert say 1m5f109y into yards where "m" =
1*1760 "f" = 5*220 and "y" = 109, which is 2969 yards in
total.I thought of a Lookup Table but that would involve
hundreds of lines.The distances would vary from 5f the
lowest to 2m7f219y the highest.Any help would be
appreciated.


--

Dave Peterson
  #4   Report Post  
David
 
Posts: n/a
Default

Hi Trevor
Thanks for your quick response.
Your function works perfectly,could you possibly help me
with the error checking part of it.My experience of
macros and functions is very limited.
Regards
David
-----Original Message-----
David

one way:

=(--LEFT(A1,FIND("m",A1)-1)*1760) +
(--MID(A1,FIND("m",A1)+1,FIND("f",A1)-FIND("m",A1)-1)

*220) +
(--MID(A1,FIND("f",A1)+1,FIND("y",A1)-FIND("f",A1)-1))

2m7f219y = 5279

You would need to enter the data in the format

aaambfcccy otherwise the
find(s) will fail and you'd get #VALUE! You could maybe

put some error
checking in as a fail safe but it would be easier to

enter 2m0f22y without
error checking than 2m22y with error checking

Regards

Trevor



"David" wrote in

message
...
How do I convert say 1m5f109y into yards where "m" =
1*1760 "f" = 5*220 and "y" = 109, which is 2969 yards

in
total.I thought of a Lookup Table but that would

involve
hundreds of lines.The distances would vary from 5f the
lowest to 2m7f219y the highest.Any help would be
appreciated.



.

  #5   Report Post  
David
 
Posts: n/a
Default


-----Original Message-----
I'd use a userdefined function:

Option Explicit
Function myConversion(myStr As String) As Variant

Dim res As Variant

myStr = LCase(myStr)
myStr = Application.Substitute(myStr, "m", "*1760+")
myStr = Application.Substitute(myStr, "f", "*220+")
myStr = Application.Substitute(myStr, "y", "")

If Right(myStr, 1) = "+" Then
myStr = Left(myStr, Len(myStr) - 1)
End If

res = Application.Evaluate(myStr)

If IsError(res) Then
myConversion = "Format Error"
Else
myConversion = res
End If

End Function

==========
If you're new to macros, you may want to read David

McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Short course:

Open your workbook.
Hit alt-f11 to get to the VBE (where macros/UDF's live)
hit ctrl-R to view the project explorer
Find your workbook.
should look like: VBAProject (yourfilename.xls)

right click on the project name
Insert, then Module
You should see the code window pop up on the right hand

side

Paste the code in there.

Now go back to excel.
Into a test cell and type:
=myconversion(a1)

David wrote:

How do I convert say 1m5f109y into yards where "m" =
1*1760 "f" = 5*220 and "y" = 109, which is 2969 yards

in
total.I thought of a Lookup Table but that would

involve
hundreds of lines.The distances would vary from 5f the
lowest to 2m7f219y the highest.Any help would be
appreciated.


--

Dave Peterson
.
Hi Dave

Thats perfect !!! thanks for your help.
Regards
David

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting selected section of text to numbers Rob Excel Discussion (Misc queries) 6 March 8th 05 01:52 AM
Converting Numbers to Text properly Shirley Munro Excel Discussion (Misc queries) 1 February 16th 05 03:01 PM
roundoff when converting text to numbers Jack Excel Worksheet Functions 3 January 30th 05 01:51 AM
converting numbers to text and prefill text field with 0's Jan Buckley Excel Discussion (Misc queries) 2 January 20th 05 09:03 PM
Converting text to numbers Scott Excel Discussion (Misc queries) 3 November 26th 04 09:17 PM


All times are GMT +1. The time now is 05:54 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"