Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Percentage formating in macro
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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Percentage formating in macro
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 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Percentage formating in macro
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 |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Percentage formating in macro
Hi Jim:
Finally it worked, what a relieve ! I was stocked in a macro which will reduce 2 hrs. of work to 1 minute just because of this formating. Thanks a lot. I could't figure out your second sugestion, but I did with the first one. The string is below. Saskour20per = Format(Saskour20per, "0%") Thanks a lot for your explanation as well. That helps me to understand variables and not to make that mistake in the future. Orquidea "Jim Cone" wrote: 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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Macro fails to produce Category Name and Percentage values - Pie C | Charts and Charting in Excel | |||
Formating percentage in macro | Excel Discussion (Misc queries) | |||
formating macro | Excel Discussion (Misc queries) | |||
macro to calculate percentage | Excel Programming | |||
Formating Macro | Excel Programming |