LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default doesn't recognize fraction in string as numeric

I'm trying to write a function to convert a string (e.g. 10' 4-1/2") to
a number. My attempt was to find the ', -, and " characters and work
around them. But I'm getting an error because IsNumeric("1/2") returns
false. Apparently Excel doesn't recognize fractions in strings as
numbers. Any ideas? Thanks. Here's my code.

Public Function ConvertStringToInches(strToConvert As String) As Double

Dim numFeet As Double, numInches As Double, numSubInches As Double
Dim intFootMark As Integer, intInchMark As Integer, intDashMark As
Integer

'find ' and " (could be ' and no " or " and no ')
intFootMark = InStr(1, strToConvert, "'", vbTextCompare)
intInchMark = InStr(1, strToConvert, Chr(34), vbTextCompare)
intDashMark = InStr(1, strToConvert, "-", vbTextCompare)

'get feet
If intFootMark 0 Then numFeet = Left(strToConvert, intFootMark -
1) Else intFootMark = -1

'get inches and subinches
If intInchMark 1 Then
If intDashMark 0 Then
numInches = Mid(strToConvert, intFootMark + 2, intDashMark
- intFootMark - 2)
numSubInches = Mid(strToConvert, intDashMark + 1,
intInchMark - intDashMark - 1)
Else
numInches = Mid(strToConvert, intFootMark + 2, intInchMark
- intFootMark - 2)
End If
End If

'multiply feet by 12 and add together
ConvertStringToInches = numFeet * 12 + numInches + numSubInches

End Function

 
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
Non Numeric String Lookup Issue slf Excel Worksheet Functions 3 July 8th 09 09:40 PM
Text string to Numeric string Manikandan[_2_] Excel Discussion (Misc queries) 2 March 12th 09 08:55 AM
Find Numeric sign in a string Nir Excel Worksheet Functions 5 November 6th 06 07:18 PM
How do I replace last numeric string from a alphanumeric string? Christy Excel Discussion (Misc queries) 3 August 11th 06 12:17 AM
Find numeric value at end of string Barb Reinhardt Excel Worksheet Functions 13 February 4th 06 11:31 PM


All times are GMT +1. The time now is 12:15 PM.

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

About Us

"It's about Microsoft Excel"