I tried to declare the variable as Range and output it in percentage format like below. But could not run accordingly.
[VBA]Dim LValue As Range
LValue = Format(0.981, "Percent")
[/VBA]
How should i change the range format to %?
I tried to declare the variable as Range and output it in percentage format like below. But could not run accordingly.
[VBA]Dim LValue As Range
LValue = Format(0.981, "Percent")
[/VBA]
How should i change the range format to %?
Good afternoon achin
When in doubt about a variable, get Excel to tell you!
You need to declare it as a string.MsgBox TypeName(LValue)
HTH
DominicB
achin
What are you actually trying to do?
That code will fail since the Format function returns a string not a range.
As is, LValue is Nothing since you didn't Set it to a cell or cells
Since the default property of the Range object is .Value, you don't really need to use LValue.Value (althougth I like to)
[vba]
Sub One()
Dim LValue As Range
Set LValue = Range("a1")
LValue = Format(0.981, "Percent")
End Sub
[/vba]
Paul
Hi, Paul!
Do you mean like this?
[VBA]
Sub One()[/VBA]
Dim LValue As Range
Set LValue = Range("a1")
.Value = Format(0.981, "Percent")
End Sub
Close
[vba]
LValue.Value = Format(0.981, "Percent")
[/vba]
Note that this would be a string that happens to look like a number. You might want to use .NumberFormat
[VBA]
Sub Two()[/VBA]
Dim LValue As Range
Set LValue = Range("a1")
LValue.Value = .981
LValue.NumberFormat = "_(#,##0.0%_);(#,##0.0%);0.0%_)"
End Sub