While defining a variable as Long, how can I format it in order to obtain the number separated with comma?
Printable View
While defining a variable as Long, how can I format it in order to obtain the number separated with comma?
Use the FormatCurrency or FormatNumber function:
VB Code:
MsgBox FormatCurrency(num) MsgBox FormatNumber(num)
very strange.. I posted an answer.. its nowhere to be found!???
hmmmmmm
For example, I have
How do I specify that I try to apply the format to this single variable?VB Code:
Dim var As Long
VB Code:
var = Format(var, "###,#0")
This works perfectly for
However it fails forVB Code:
Dim var As Long var = Format(var, "###,#0") Range("A1").Value = var
Is it possible to make a union with a formated variable?VB Code:
Dim var As Long var = Format(var, "###,#0") Range("A1").Value = "(" & - var ", " & var & ")"
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")