View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Jim Cone Jim Cone is offline
external usenet poster
 
Posts: 3,290
Default Percentage formating in macro


A Double type variable does not have properties.
So .Value and .NumberFormat cannot be used with them.
However, .Value and .NumberFormat do apply to a range object (cells).

There is a "Format" function that will format strings or numbers, so this should work...
Dim strNum as String
strNum = Format(Saskour20per,"0.00%")
Msgbox strNum

For what it is worth: Paul Lomax in his book "VB & VBA in a Nutshell" states that
the "Format function is possibly the most complex single function in VB"
(try Format(Saskour20per,"Percent")
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)



"orquidea"
wrote in message
Hi Jim
Thanks for replying back.
The three variables are declared as Double. When I run the macro I get the
message "invalid qualifier" and it highlights the row underlined. I don't
get any result. If I take off the word ".Value" and run the macro again it
gives me the same error and hightlights the same variable at the next row.

Saskour20per.Value = (saskour20 / sask20)
---------------
Saskour20per.NumberFormat = "0.00%"

I tested the macro before with the below procedure and I got the result in
decimals. The calculations are correct.

If sask20 < 0 Then
Saskour20per = (saskour20 / sask20)
End If

Thanks
Orquidea

"Jim Cone" wrote:


To help us help you...
How are the three variables declared?
sask20
saskour20
Saskour20per
What are they returning when the error occurs?
Which line generates the error?
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)



"orquidea"
wrote in message
Hi All:
I want to get the result in saskour20per as a percentage. I wrote the below
procedure which is generating the error "invalid qualifier".

Saskour20per.Value = (saskour20 / sask20)
Saskour20per.NumberFormat = "0.00%"

Could anyone help me to debug this macro?
Thanks in advance
Orquidea