Convert Feet to Milimeters (Ft to MM) and also with operators

MSRoach

New Member
Joined
Feb 23, 2013
Messages
6
I have written the following routine that will convert the range that I've selected from Feet to MM. The problem is that I've found that there are a lot of ranges that have operators such as: <30 or 10 - 20 or >60. I need to parse this text so that the result is a string that has the same operators (<,>,-), but the numerical values are converted.

Examples:

"<30" returns "<9144"
"10 - 20" returns "3048 - 6096"

The numerical conversion:
Code:
Public Sub Ft_to_mm()
    
    Dim SelRange As Range
    Dim C As Range
    
    Set SelRange = Selection
    
    For Each C In SelRange
        If IsNumeric(C) And C <> "" Then    'Range contains a number to convert
                C.Value = C.Value * 304.8
                C.NumberFormat = "0"
        Else                                'Range contains <, >, -...
                                            'break up the string
                                            
              '  "CODE HERE ?"
                                            
        End If
      Next
End Sub
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
I have written the following routine that will convert the range that I've selected from Feet to MM. The problem is that I've found that there are a lot of ranges that have operators such as: <30 or 10 - 20 or >60. I need to parse this text so that the result is a string that has the same operators (<,>,-), but the numerical values are converted.
Are you numbers always composed of digits only? Or could have comma delimited values or numbers in powers of ten (scientific notation)?
 
Upvote 0
Are you numbers always composed of digits only? Or could have comma delimited values or numbers in powers of ten (scientific notation)?

The number portion of the string is only numbers. <12,340 does not exist. It is always in the form N, *N, N*, N*N where N is a number without any notation such as commas or exponential information. * is a string that should be repeated back after the conversion. So the answer is in the form CN, *CN, CN*, CN*CN where CN is a converted number.
 
Upvote 0
The number portion of the string is only numbers. <12,340 does not exist. It is always in the form N, *N, N*, N*N where N is a number without any notation such as commas or exponential information. * is a string that should be repeated back after the conversion. So the answer is in the form CN, *CN, CN*, CN*CN where CN is a converted number.
Okay, see if this macro does what you want...
Code:
Public Sub Ft_to_mm()
  Dim C As Range, X As Long, Original As String, Temp As String, FT() As String, MM() As String
  For Each C In Selection
    Original = C.Value
    Temp = Original
    For X = 1 To Len(Temp)
      If Mid(Temp, X, 1) Like "[!0-9]" Then
        Mid(Temp, X) = " "
      End If
    Next
    FT = Split(WorksheetFunction.Trim(Temp))
    ReDim MM(0 To UBound(FT))
    If UBound(FT) > -1 Then
      For X = 0 To UBound(FT)
        MM(X) = CStr(FT(X) * 304.8)
      Next
    End If
    For X = 0 To UBound(FT)
      Original = WorksheetFunction.Replace(Original, InStr(Original, FT(X)), Len(FT(X)), MM(X))
    Next
    C.Value = Original
  Next
End Sub
 
Upvote 0
Thank you -

This works unless there is a merged cell. In that case it's actually recycling the result from the first run.

Also, can you set the format of the number to "0". It is out putting "0.0"

Thanks again
 
Upvote 0

Forum statistics

Threads
1,223,530
Messages
6,172,859
Members
452,485
Latest member
Savman

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