|
-
Jun 2nd, 2006, 12:44 PM
#1
Thread Starter
Addicted Member
RESOLVED[Variable format]
While defining a variable as Long, how can I format it in order to obtain the number separated with comma?
Last edited by Fonty; Jun 3rd, 2006 at 10:39 PM.
-
Jun 2nd, 2006, 12:50 PM
#2
Re: Variable format
Use the FormatCurrency or FormatNumber function:
VB Code:
MsgBox FormatCurrency(num)
MsgBox FormatNumber(num)
-
Jun 2nd, 2006, 12:53 PM
#3
Re: Variable format
very strange.. I posted an answer.. its nowhere to be found!???
hmmmmmm
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Jun 2nd, 2006, 01:39 PM
#4
Thread Starter
Addicted Member
Re: Variable format
For example, I have
How do I specify that I try to apply the format to this single variable?
-
Jun 2nd, 2006, 01:55 PM
#5
Re: Variable format
VB Code:
var = Format(var, "###,#0")
-
Jun 2nd, 2006, 03:15 PM
#6
Thread Starter
Addicted Member
Re: Variable format
This works perfectly for
VB Code:
Dim var As Long
var = Format(var, "###,#0")
Range("A1").Value = var
However it fails for
VB Code:
Dim var As Long
var = Format(var, "###,#0")
Range("A1").Value = "(" & - var ", " & var & ")"
Is it possible to make a union with a formated variable?
-
Jun 3rd, 2006, 05:22 AM
#7
Re: Variable format
As var is declared as a Long, it cannot contain the formatting (only the numbers). You need to use the format function when you are converting the value to a string, eg:
VB Code:
Dim var As Long
Range("A1").Value = "(-" & Format(var, "###,#0") ", " & Format(var, "###,#0") & ")"
Your first example should be:
VB Code:
Dim var As Long
Range("A1").Value = Format(var, "###,#0")
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|