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: 345
Default Custom String Format

Hi All,
After reading the help on Format, I don't know
what I missed on trying to format a code with
a bit of custom text. Clearly I would like to
avoid the last brute force method. There were no
examples I saw that fit in the programming
community for Excel.

Where did I go wrong?
Thanks,
Neal


Sub Format_Apply_Fmt_To_Var()
Dim gsWbkFmtAy(1 To 2) As String, Cd As String, Desc As String
gsWbkFmtAy(1) = "Rte Wbk"
gsWbkFmtAy(2) = "Other"

Cd = "1"
Desc = Format(Cd, gsWbkFmtAy(Val(Cd)))
Debug.Print Desc & " 1 s/b: Rte Wbk"
' result is: Rte 1bk

Cd = "2"
Desc = Format(Cd, gsWbkFmtAy(Val(Cd)))
Debug.Print Desc & " 2 s/b: Other"
' result is: Oth0er

Cd = "a"
Desc = Format(Cd, gsWbkFmtAy(1))
Debug.Print Desc & " a s/b: Rte Wbk"
' result is: a

Cd = "b"
Desc = Format(Cd, gsWbkFmtAy(2))
Debug.Print Desc & " b s/b: Other"
' result is: b

'exasperation
Dim Ix As Integer
Desc = ""
Cd = "1"
For Ix = 1 To UBound(gsWbkFmtAy)
If Ix = Val(Cd) Then Desc = gsWbkFmtAy(Ix): Exit For
Next Ix
Debug.Print Desc & " brute force for 1"
' as expected, Rte Wbk
Exit Sub
--
Neal Z
 
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
Need help with converting CUSTOM format/TEXT format to DATE format Deo Cleto Excel Worksheet Functions 6 June 2nd 09 08:14 PM
Format Cell as custom type but data doesn't display like I custom. ToMMie Excel Discussion (Misc queries) 6 September 11th 08 08:31 AM
Excel 2003. Custom format gets replaced by Special format. jasper New Users to Excel 0 September 1st 08 03:46 AM
Converting a time format to a String format in Excel Bill Partridge Excel Discussion (Misc queries) 3 October 3rd 07 11:48 AM
how do I add phone number format as a permanent custom format? frustratedagain Excel Discussion (Misc queries) 3 February 4th 06 03:52 AM


All times are GMT +1. The time now is 02:17 PM.

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

About Us

"It's about Microsoft Excel"