Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 132
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 132
Default 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   Report Post  
Posted to microsoft.public.excel.programming
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




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 132
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro fails to produce Category Name and Percentage values - Pie C Jay Charts and Charting in Excel 5 June 19th 09 09:24 AM
Formating percentage in macro orquidea Excel Discussion (Misc queries) 2 December 19th 07 01:38 AM
formating macro vishu Excel Discussion (Misc queries) 6 June 15th 05 01:02 PM
macro to calculate percentage vikram Excel Programming 5 May 3rd 04 04:02 PM
Formating Macro Brady Snow Excel Programming 2 November 4th 03 04:18 PM


All times are GMT +1. The time now is 04:13 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"