Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-11-2014, 11:07 PM
macropod's Avatar
macropod macropod is offline Search a cell that contains words and numbers and convert the numbers to metric Windows 7 64bit Search a cell that contains words and numbers and convert the numbers to metric Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,375
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Here's some code to get you started:


Code:
Sub Demo()
Dim lRow As Long, i As Long, j As Long, k As Long, StrTmp As String, StrOut As String
With ActiveSheet.UsedRange
  'Loop through each cell in column C
  For i = 3 To .Cells.SpecialCells(xlCellTypeLastCell).Row
    With .Cells(i, 3)
      StrOut = ""
      'Split the cell results by spaces for parsing
      k = UBound(Split(.Text, " "))
      'Process each 'word'
      For j = 0 To k
        StrTmp = Split(.Text, " ")(j)
        'See what the 'word' ends with
        Select Case Right(StrTmp, 1)
          'If it ends with ', try a ft:m conversion
          Case "'"
            StrTmp = Split(StrTmp, "'")(0)
            If IsNumeric(StrTmp) Then
              StrOut = StrOut & " " & Format(StrTmp * 0.3048, "0.00") & "m" & " (" & StrTmp & "')"
            Else
              StrOut = StrOut & " " & StrTmp
            End If
          'If it ends with ", try a in:cm conversion
          Case """"
            StrTmp = Split(StrTmp, """")(0)
            If IsNumeric(StrTmp) Then
              StrOut = StrOut & " " & Format(StrTmp * 2.54, "0.00") & "cm" & " (" & StrTmp & """)"
            'If it ends with " and contains ', try a ft&in:cm conversion
            ElseIf InStr(StrTmp, "'") > 0 Then
              If IsNumeric(Split(StrTmp, "'")(0)) And IsNumeric(Split(StrTmp, "'")(1)) Then
                StrOut = StrOut & " " & Format(Split(StrTmp, "'")(0) * 0.3048 + Split(StrTmp, "'")(1) * 2.54, "0.00") & "cm" & " (" & StrTmp & """)"
              Else
                StrOut = StrOut & " " & StrTmp
              End If
            Else
              StrOut = StrOut & " " & StrTmp
            End If
          Case Else
            'If it's not ft/in, look for other possibilities
            If IsNumeric(StrTmp) And j < k Then
              'If the next 'word' is GPM, do a GPM:CMH conversion
              If Split(.Text, " ")(j + 1) = "GPM" Then
                StrOut = StrOut & " " & Format(StrTmp / 1000 * 3.78544 * 60, "0.00") & " CMH" & " (" & StrTmp & " GPM)"
                j = j + 1
              Else
                StrOut = StrOut & " " & StrTmp
              End If
            Else
              StrOut = StrOut & " " & StrTmp
            End If
        End Select
      Next
        .Value = StrOut
    End With
  Next
End With
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Words in my document were converted to numbers???? MikeD23 Word 1 08-26-2012 11:09 AM
can word convert numbers? koolfire Word 2 01-07-2012 02:12 PM
Search a cell that contains words and numbers and convert the numbers to metric Convert numbers to a specific text string francis Excel 1 10-06-2011 01:43 PM
Numbers in Words janak Excel 2 12-19-2010 08:53 PM
Numbers Convert in word in MS Access towhid Office 0 08-19-2010 01:17 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:14 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft