Help with VBA Code

alguzman

Registered User.
Local time
Today, 18:47
Joined
Aug 2, 2001
Messages
63
I'm having trouble with what might seem to be simple coding for the seasoned VBA pro. What I want to do is have a number entered like 127 and then have it show as text like One Two Seven. Can any one help me out. My example code is below.

Dim MyNumber, MyText
MyDouble = 127
MyText = CStr(MyDouble)

I'm new to VBA and I thought the Cstr statement will convert the 127 to one- two -seven but it actually takes the integer 127 and displays it as 127 in string format. Again I want to show text One- Two- Seven. Any help would be great, this has been taking me days to figure out. :confused:
 
Use a Do Loop to go through that converted text string and build a new text string, substituting "One-" for 1, "Seven-" for 7, etc. Then at the end cut off the last character (that stray "-") and you'll have the answer you want.

The Len() and Mid() functions will help with what you want, and your text conversion will be easier with Select().

If you get stuck post back.
 
Last edited:
Can't think of a function, though there must be one. Here is a longwinded way of doing it

Function Test()
Dim MyNumber, MyVal, x
Dim StrMsg As String
MyNumber = 127
StrMsg = ""
For x = 1 To Len(MyNumber)
MyVal = Right(Left(MyNumber, x), 1)
Select Case MyVal
Case 1
StrMsg = StrMsg & " One"
Case 2
StrMsg = StrMsg & " Two"
Case 7
StrMsg = StrMsg & " Seven"
End Select
Next x
MsgBox StrMsg
End Function

You will need to finish off your case statement to fill in the missing numbers

HTH
 
thanks

Thanks I will give both a shot and let you know how I made out.:)
 

Users who are viewing this thread

Back
Top Bottom