Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Thomas Evans   on Jan 23 In MS Office Category.

  
Question Answered By: Andrew Bryant   on Jan 23

Here is a UDF to get you started

Function GetNumber(text As Variant, n As Integer) As String

'=getnumber(A1,0)for the text

'=getnumber(A1,1)for the number

Dim i As Long

Dim NumStr As String

Dim txt As String

Dim TxtStr As String

Dim TmpStr As String

Dim Words As Variant



txt = Trim(text)

NumStr = ""

TxtStr = ""



Words = Split(txt, " ")

For i = 0 To UBound(Words)



TmpStr = Replace(Words(i), "-", "")



If IsNumeric(TmpStr) And Len(TmpStr) > 2 Then

NumStr = TmpStr

Else

TxtStr = TxtStr + IIf(i > 1, " ", "") + Words(i)

End If



Next i



GetNumber = IIf(n = 1, NumStr, TxtStr)



End Function

Share: 

 

This Question has 17 more answer(s). View Complete Question Thread

 


Tagged: