Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 69
Default Decimal problem

In a VBA project I'm supporting, I ran into a line where a cell is assigned the value

"=RC[4] / (" + Format(100 - dblNewProdSaving) + " / 100)"

I get a run-time error on this line. However, if I manually change the cell from where dblNewProdSaving is taken, from 0,02 to 0.02, it runs. Why is this and what can I do about it?

Gustaf
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,049
Default Decimal problem

syntax for format is wrong

"=RC[4] / (" + Format(100 - dblNewProdSaving ,"0.00" ) + " / 100)"

but i suggest

with rangetarget
.formulaR1C1 = "=RC[4] / (" & (100 - dblNewProdSaving ) & ")"
.NumberFormat ="0.00%"
end with

format the result generally overcomes issues with results that can often
unexpectedly occur when an interim calculation is formatted , eg rounding
issue


"Gustaf" wrote in message
...
In a VBA project I'm supporting, I ran into a line where a cell is
assigned the value

"=RC[4] / (" + Format(100 - dblNewProdSaving) + " / 100)"

I get a run-time error on this line. However, if I manually change the
cell from where dblNewProdSaving is taken, from 0,02 to 0.02, it runs. Why
is this and what can I do about it?
Gustaf


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,049
Default Decimal problem

syntax for format is wrong

"=RC[4] / (" + Format(100 - dblNewProdSaving ,"0.00" ) + " / 100)"

but i suggest

with rangetarget
.formulaR1C1 = "=RC[4] / (" & (100 - dblNewProdSaving ) & ")"
.NumberFormat ="0.00%"
end with

format the result generally overcomes issues with results that can often
unexpectedly occur when an interim calculation is formatted , eg rounding
issue


"Gustaf" wrote in message
...
In a VBA project I'm supporting, I ran into a line where a cell is
assigned the value

"=RC[4] / (" + Format(100 - dblNewProdSaving) + " / 100)"

I get a run-time error on this line. However, if I manually change the
cell from where dblNewProdSaving is taken, from 0,02 to 0.02, it runs. Why
is this and what can I do about it?
Gustaf


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 69
Default Decimal problem

Patrick Molloy wrote:

syntax for format is wrong

"=RC[4] / (" + Format(100 - dblNewProdSaving ,"0.00" ) + " / 100)"


That's what I thought too, but I get the same error. By the way, am I right that VBA always expects "." as decimal sign, regardless of my regional settings?

but i suggest

with rangetarget
.formulaR1C1 = "=RC[4] / (" & (100 - dblNewProdSaving ) & ")"
.NumberFormat ="0.00%"
end with


Sorry to say, but this also produces the same error: "Application defined or object defined error" (duh!). Also tried putting NumberFormat first.

As an alternative, I tried changing the format of the cell from which I take dblNewProdSaving:

dblNewProdSaving = Format(ws.Cells(5, 4), "0.00%")

But this results in a "type mismatch" error. Ideally, I'd like to change it behind the scenes, to avoid confusing the user.

Gustaf
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 69
Default Decimal problem

Patrick Molloy wrote:

syntax for format is wrong

"=RC[4] / (" + Format(100 - dblNewProdSaving ,"0.00" ) + " / 100)"


That's what I thought too, but I get the same error. By the way, am I right that VBA always expects "." as decimal sign, regardless of my regional settings?

but i suggest

with rangetarget
.formulaR1C1 = "=RC[4] / (" & (100 - dblNewProdSaving ) & ")"
.NumberFormat ="0.00%"
end with


Sorry to say, but this also produces the same error: "Application defined or object defined error" (duh!). Also tried putting NumberFormat first.

As an alternative, I tried changing the format of the cell from which I take dblNewProdSaving:

dblNewProdSaving = Format(ws.Cells(5, 4), "0.00%")

But this results in a "type mismatch" error. Ideally, I'd like to change it behind the scenes, to avoid confusing the user.

Gustaf


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,049
Default Decimal problem

what's the value in dblNewProdSaving when you step through?

"Gustaf" wrote in message
...
Patrick Molloy wrote:

syntax for format is wrong

"=RC[4] / (" + Format(100 - dblNewProdSaving ,"0.00" ) + " / 100)"


That's what I thought too, but I get the same error. By the way, am I
right that VBA always expects "." as decimal sign, regardless of my
regional settings?

but i suggest

with rangetarget
.formulaR1C1 = "=RC[4] / (" & (100 - dblNewProdSaving ) & ")"
.NumberFormat ="0.00%"
end with


Sorry to say, but this also produces the same error: "Application defined
or object defined error" (duh!). Also tried putting NumberFormat first.

As an alternative, I tried changing the format of the cell from which I
take dblNewProdSaving:

dblNewProdSaving = Format(ws.Cells(5, 4), "0.00%")

But this results in a "type mismatch" error. Ideally, I'd like to change
it behind the scenes, to avoid confusing the user.

Gustaf


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,049
Default Decimal problem

what's the value in dblNewProdSaving when you step through?

"Gustaf" wrote in message
...
Patrick Molloy wrote:

syntax for format is wrong

"=RC[4] / (" + Format(100 - dblNewProdSaving ,"0.00" ) + " / 100)"


That's what I thought too, but I get the same error. By the way, am I
right that VBA always expects "." as decimal sign, regardless of my
regional settings?

but i suggest

with rangetarget
.formulaR1C1 = "=RC[4] / (" & (100 - dblNewProdSaving ) & ")"
.NumberFormat ="0.00%"
end with


Sorry to say, but this also produces the same error: "Application defined
or object defined error" (duh!). Also tried putting NumberFormat first.

As an alternative, I tried changing the format of the cell from which I
take dblNewProdSaving:

dblNewProdSaving = Format(ws.Cells(5, 4), "0.00%")

But this results in a "type mismatch" error. Ideally, I'd like to change
it behind the scenes, to avoid confusing the user.

Gustaf


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 69
Default Decimal problem

Patrick Molloy wrote:

what's the value in dblNewProdSaving when you step through?


The value is 0,02 in the cell and still 0,02 when transfered to dblNewProdSaving. If I change the cell to 0.02 the value of dblNewProdSaving becomes 2 when I step through. Looks odd but probably makes sense, because the variable is a percentage.

Gustaf
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 69
Default Decimal problem

Patrick Molloy wrote:

what's the value in dblNewProdSaving when you step through?


The value is 0,02 in the cell and still 0,02 when transfered to dblNewProdSaving. If I change the cell to 0.02 the value of dblNewProdSaving becomes 2 when I step through. Looks odd but probably makes sense, because the variable is a percentage.

Gustaf
  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,049
Default Decimal problem

that makes a pretty big difference!

so
"=RC[4] / (" & (100 - dblNewProdSaving ) & ")"

should be

"=RC[4] / (" & (1 - dblNewProdSaving ) & ")"


"Gustaf" wrote in message
...
Patrick Molloy wrote:

what's the value in dblNewProdSaving when you step through?


The value is 0,02 in the cell and still 0,02 when transfered to
dblNewProdSaving. If I change the cell to 0.02 the value of
dblNewProdSaving becomes 2 when I step through. Looks odd but probably
makes sense, because the variable is a percentage.

Gustaf




  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,049
Default Decimal problem

that makes a pretty big difference!

so
"=RC[4] / (" & (100 - dblNewProdSaving ) & ")"

should be

"=RC[4] / (" & (1 - dblNewProdSaving ) & ")"


"Gustaf" wrote in message
...
Patrick Molloy wrote:

what's the value in dblNewProdSaving when you step through?


The value is 0,02 in the cell and still 0,02 when transfered to
dblNewProdSaving. If I change the cell to 0.02 the value of
dblNewProdSaving becomes 2 when I step through. Looks odd but probably
makes sense, because the variable is a percentage.

Gustaf


  #12   Report Post  
Posted to microsoft.public.excel.programming
jaf jaf is offline
external usenet poster
 
Posts: 300
Default Decimal problem

"By the way, am I right that VBA always expects "." as decimal sign, regardless of my regional settings?"
Gustaf


No. It's governed by regional settings.

John
  #13   Report Post  
Posted to microsoft.public.excel.programming
jaf jaf is offline
external usenet poster
 
Posts: 300
Default Decimal problem

"By the way, am I right that VBA always expects "." as decimal sign, regardless of my regional settings?"
Gustaf


No. It's governed by regional settings.

John
  #14   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Decimal problem

"By the way, am I right that VBA always expects "." as decimal sign, regardless of my regional settings?"
Gustaf


No. It's governed by regional settings.


But the regional settings can be overridden in Excel.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)


On Wed, 3 Jun 2009 12:09:39 -0400, "jaf" wrote:

"By the way, am I right that VBA always expects "." as decimal sign, regardless of my regional settings?"
Gustaf


No. It's governed by regional settings.

John

  #15   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Decimal problem

"By the way, am I right that VBA always expects "." as decimal sign, regardless of my regional settings?"
Gustaf


No. It's governed by regional settings.


But the regional settings can be overridden in Excel.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)


On Wed, 3 Jun 2009 12:09:39 -0400, "jaf" wrote:

"By the way, am I right that VBA always expects "." as decimal sign, regardless of my regional settings?"
Gustaf


No. It's governed by regional settings.

John



  #16   Report Post  
Posted to microsoft.public.excel.programming
jaf jaf is offline
external usenet poster
 
Posts: 300
Default Decimal problem

Hi Chip,
Yes, I should have pointed that out also.
Toolsoptionsinternational "system separators"

John


"Chip Pearson" wrote in message ...
"By the way, am I right that VBA always expects "." as decimal sign, regardless of my regional settings?"
Gustaf


No. It's governed by regional settings.


But the regional settings can be overridden in Excel.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)


On Wed, 3 Jun 2009 12:09:39 -0400, "jaf" wrote:

"By the way, am I right that VBA always expects "." as decimal sign, regardless of my regional settings?"
Gustaf


No. It's governed by regional settings.

John

  #17   Report Post  
Posted to microsoft.public.excel.programming
jaf jaf is offline
external usenet poster
 
Posts: 300
Default Decimal problem

Hi Chip,
Yes, I should have pointed that out also.
Toolsoptionsinternational "system separators"

John


"Chip Pearson" wrote in message ...
"By the way, am I right that VBA always expects "." as decimal sign, regardless of my regional settings?"
Gustaf


No. It's governed by regional settings.


But the regional settings can be overridden in Excel.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)


On Wed, 3 Jun 2009 12:09:39 -0400, "jaf" wrote:

"By the way, am I right that VBA always expects "." as decimal sign, regardless of my regional settings?"
Gustaf


No. It's governed by regional settings.

John

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
Problem With Decimal Point sifuconman Excel Programming 2 August 3rd 06 02:11 PM
Problem with decimal format Richard RE Excel Worksheet Functions 2 June 22nd 06 05:49 PM
Decimal problem Mats Samson Excel Programming 3 February 20th 06 04:36 PM
problem with decimal in calculation Amanda Excel Discussion (Misc queries) 5 January 12th 06 05:25 PM
Decimal translation problem Francis Hayes (The Excel Addict) Excel Discussion (Misc queries) 1 January 21st 05 02:15 PM


All times are GMT +1. The time now is 11:26 PM.

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"