Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Number variable loses format on write

Have have a varibale declared as a double, read a number into it from a file.
THe variable is indicated with four decimal places when viewed in the
debugger. When I write the variable out to Excel using the following the
number gets truncated to two decimal places:

With ActiveWorkbook.Worksheets("Dump Area")
.Cells(RowNumber, 2) = AreaCounts

Anyone have any suggestions to fix this problem?

Thanks !



--
Ray
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Number variable loses format on write

If you look in the formulabar, do you see all 4 decimals?

If yes, try widening the column.

If no, what value do you see in the debugger and what value do you see in the
formulabar?

Halray wrote:

Have have a varibale declared as a double, read a number into it from a file.
THe variable is indicated with four decimal places when viewed in the
debugger. When I write the variable out to Excel using the following the
number gets truncated to two decimal places:

With ActiveWorkbook.Worksheets("Dump Area")
.Cells(RowNumber, 2) = AreaCounts

Anyone have any suggestions to fix this problem?

Thanks !

--
Ray


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Number variable loses format on write

Two decimal places are displayed in the formula bar. In the debugger the
varibale has four decimal places.

--
Ray


"Dave Peterson" wrote:

If you look in the formulabar, do you see all 4 decimals?

If yes, try widening the column.

If no, what value do you see in the debugger and what value do you see in the
formulabar?

Halray wrote:

Have have a varibale declared as a double, read a number into it from a file.
THe variable is indicated with four decimal places when viewed in the
debugger. When I write the variable out to Excel using the following the
number gets truncated to two decimal places:

With ActiveWorkbook.Worksheets("Dump Area")
.Cells(RowNumber, 2) = AreaCounts

Anyone have any suggestions to fix this problem?

Thanks !

--
Ray


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 770
Default Number variable loses format on write

Halray,

I think that if the cell your setting already has a format it might cause
what you're seeing, so try setting the format:

With ActiveWorkbook.Worksheets("Dump Area").Cells(RowNumber, 2)
.Value = AreaCounts
.NumberFormat = "#.0000"
End With

hth,

Doug

"Halray" wrote in message
...
Have have a varibale declared as a double, read a number into it from a

file.
THe variable is indicated with four decimal places when viewed in the
debugger. When I write the variable out to Excel using the following the
number gets truncated to two decimal places:

With ActiveWorkbook.Worksheets("Dump Area")
.Cells(RowNumber, 2) = AreaCounts

Anyone have any suggestions to fix this problem?

Thanks !



--
Ray



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Number variable loses format on write

Sorry that format has no affect either before or after the write.
--
Ray


"Doug Glancy" wrote:

Halray,

I think that if the cell your setting already has a format it might cause
what you're seeing, so try setting the format:

With ActiveWorkbook.Worksheets("Dump Area").Cells(RowNumber, 2)
.Value = AreaCounts
.NumberFormat = "#.0000"
End With

hth,

Doug

"Halray" wrote in message
...
Have have a varibale declared as a double, read a number into it from a

file.
THe variable is indicated with four decimal places when viewed in the
debugger. When I write the variable out to Excel using the following the
number gets truncated to two decimal places:

With ActiveWorkbook.Worksheets("Dump Area")
.Cells(RowNumber, 2) = AreaCounts

Anyone have any suggestions to fix this problem?

Thanks !



--
Ray






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 770
Default Number variable loses format on write

Based on your answer to Dave's question, I can now see that it wouldn't.
Hopefully, he'll have an answer.

Doug

"Halray" wrote in message
...
Sorry that format has no affect either before or after the write.
--
Ray


"Doug Glancy" wrote:

Halray,

I think that if the cell your setting already has a format it might

cause
what you're seeing, so try setting the format:

With ActiveWorkbook.Worksheets("Dump Area").Cells(RowNumber, 2)
.Value = AreaCounts
.NumberFormat = "#.0000"
End With

hth,

Doug

"Halray" wrote in message
...
Have have a varibale declared as a double, read a number into it from

a
file.
THe variable is indicated with four decimal places when viewed in the
debugger. When I write the variable out to Excel using the following

the
number gets truncated to two decimal places:

With ActiveWorkbook.Worksheets("Dump Area")
.Cells(RowNumber, 2) = AreaCounts

Anyone have any suggestions to fix this problem?

Thanks !



--
Ray






  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Number variable loses format on write

AreaCount# = 1234.5678
? typename(areacount)
Double
ActiveCell.Value = Areacount#
? ActiveCell.Value
1234.5678
? activeCell.Text
1234.568

--
Regards,
Tom Ogilvy

"Halray" wrote in message
...
Two decimal places are displayed in the formula bar. In the debugger the
varibale has four decimal places.

--
Ray


"Dave Peterson" wrote:

If you look in the formulabar, do you see all 4 decimals?

If yes, try widening the column.

If no, what value do you see in the debugger and what value do you see

in the
formulabar?

Halray wrote:

Have have a varibale declared as a double, read a number into it from

a file.
THe variable is indicated with four decimal places when viewed in the
debugger. When I write the variable out to Excel using the following

the
number gets truncated to two decimal places:

With ActiveWorkbook.Worksheets("Dump Area")
.Cells(RowNumber, 2) = AreaCounts

Anyone have any suggestions to fix this problem?

Thanks !

--
Ray


--

Dave Peterson



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Number variable loses format on write

Hmmm. What are the two numbers?

Then we can try some simple tests.

Halray wrote:

Two decimal places are displayed in the formula bar. In the debugger the
varibale has four decimal places.

--
Ray

"Dave Peterson" wrote:

If you look in the formulabar, do you see all 4 decimals?

If yes, try widening the column.

If no, what value do you see in the debugger and what value do you see in the
formulabar?

Halray wrote:

Have have a varibale declared as a double, read a number into it from a file.
THe variable is indicated with four decimal places when viewed in the
debugger. When I write the variable out to Excel using the following the
number gets truncated to two decimal places:

With ActiveWorkbook.Worksheets("Dump Area")
.Cells(RowNumber, 2) = AreaCounts

Anyone have any suggestions to fix this problem?

Thanks !

--
Ray


--

Dave Peterson


--

Dave Peterson
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Number variable loses format on write

One more guess.

If the cell is formatted to show 2 decimals and you have
Tools|Options|calculation tab|precision as displayed checked, it could cause
what you describe.

With ActiveCell
.NumberFormat = "0.00"
.Value = "1234.1234"
MsgBox .Value
End With



Halray wrote:

Two decimal places are displayed in the formula bar. In the debugger the
varibale has four decimal places.

--
Ray

"Dave Peterson" wrote:

If you look in the formulabar, do you see all 4 decimals?

If yes, try widening the column.

If no, what value do you see in the debugger and what value do you see in the
formulabar?

Halray wrote:

Have have a varibale declared as a double, read a number into it from a file.
THe variable is indicated with four decimal places when viewed in the
debugger. When I write the variable out to Excel using the following the
number gets truncated to two decimal places:

With ActiveWorkbook.Worksheets("Dump Area")
.Cells(RowNumber, 2) = AreaCounts

Anyone have any suggestions to fix this problem?

Thanks !

--
Ray


--

Dave Peterson


--

Dave Peterson
  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Number variable loses format on write

Dave,

I've been away, but now that I check what you say I do not have that option
checked. Any more ideas?
--
Ray


"Dave Peterson" wrote:

One more guess.

If the cell is formatted to show 2 decimals and you have
Tools|Options|calculation tab|precision as displayed checked, it could cause
what you describe.

With ActiveCell
.NumberFormat = "0.00"
.Value = "1234.1234"
MsgBox .Value
End With



Halray wrote:

Two decimal places are displayed in the formula bar. In the debugger the
varibale has four decimal places.

--
Ray

"Dave Peterson" wrote:

If you look in the formulabar, do you see all 4 decimals?

If yes, try widening the column.

If no, what value do you see in the debugger and what value do you see in the
formulabar?

Halray wrote:

Have have a varibale declared as a double, read a number into it from a file.
THe variable is indicated with four decimal places when viewed in the
debugger. When I write the variable out to Excel using the following the
number gets truncated to two decimal places:

With ActiveWorkbook.Worksheets("Dump Area")
.Cells(RowNumber, 2) = AreaCounts

Anyone have any suggestions to fix this problem?

Thanks !

--
Ray

--

Dave Peterson


--

Dave Peterson



  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Number variable loses format on write

Thanks for trying to help - I'm still looking for an answer.

Thanks again!!!
--
Ray


"Doug Glancy" wrote:

Based on your answer to Dave's question, I can now see that it wouldn't.
Hopefully, he'll have an answer.

Doug

"Halray" wrote in message
...
Sorry that format has no affect either before or after the write.
--
Ray


"Doug Glancy" wrote:

Halray,

I think that if the cell your setting already has a format it might

cause
what you're seeing, so try setting the format:

With ActiveWorkbook.Worksheets("Dump Area").Cells(RowNumber, 2)
.Value = AreaCounts
.NumberFormat = "#.0000"
End With

hth,

Doug

"Halray" wrote in message
...
Have have a varibale declared as a double, read a number into it from

a
file.
THe variable is indicated with four decimal places when viewed in the
debugger. When I write the variable out to Excel using the following

the
number gets truncated to two decimal places:

With ActiveWorkbook.Worksheets("Dump Area")
.Cells(RowNumber, 2) = AreaCounts

Anyone have any suggestions to fix this problem?

Thanks !



--
Ray






  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Number variable loses format on write

None from me.

But you never said what the numbers were!

Halray wrote:

Dave,

I've been away, but now that I check what you say I do not have that option
checked. Any more ideas?
--
Ray

"Dave Peterson" wrote:

One more guess.

If the cell is formatted to show 2 decimals and you have
Tools|Options|calculation tab|precision as displayed checked, it could cause
what you describe.

With ActiveCell
.NumberFormat = "0.00"
.Value = "1234.1234"
MsgBox .Value
End With



Halray wrote:

Two decimal places are displayed in the formula bar. In the debugger the
varibale has four decimal places.

--
Ray

"Dave Peterson" wrote:

If you look in the formulabar, do you see all 4 decimals?

If yes, try widening the column.

If no, what value do you see in the debugger and what value do you see in the
formulabar?

Halray wrote:

Have have a varibale declared as a double, read a number into it from a file.
THe variable is indicated with four decimal places when viewed in the
debugger. When I write the variable out to Excel using the following the
number gets truncated to two decimal places:

With ActiveWorkbook.Worksheets("Dump Area")
.Cells(RowNumber, 2) = AreaCounts

Anyone have any suggestions to fix this problem?

Thanks !

--
Ray

--

Dave Peterson


--

Dave Peterson


--

Dave Peterson
  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Number variable loses format on write

Dave,

Thanks for trying to help. The fix was to use a variable declared with the
pound symbol on the end. I'm not sure why that symbol matters, but it
worked. I did the following:


With ActiveWorkbook.Worksheets("Dump Area")
.Cells(RowNumber, 3) = RetentionTime
area_summed# = AreaSum
.Cells(RowNumber, 2) = area_summed#
'output paraffin area counts to column-4
area# = AreaCounts
.Cells(RowNumber, 4) = area#
End With

--
Ray


"Dave Peterson" wrote:

None from me.

But you never said what the numbers were!

Halray wrote:

Dave,

I've been away, but now that I check what you say I do not have that option
checked. Any more ideas?
--
Ray

"Dave Peterson" wrote:

One more guess.

If the cell is formatted to show 2 decimals and you have
Tools|Options|calculation tab|precision as displayed checked, it could cause
what you describe.

With ActiveCell
.NumberFormat = "0.00"
.Value = "1234.1234"
MsgBox .Value
End With



Halray wrote:

Two decimal places are displayed in the formula bar. In the debugger the
varibale has four decimal places.

--
Ray

"Dave Peterson" wrote:

If you look in the formulabar, do you see all 4 decimals?

If yes, try widening the column.

If no, what value do you see in the debugger and what value do you see in the
formulabar?

Halray wrote:

Have have a varibale declared as a double, read a number into it from a file.
THe variable is indicated with four decimal places when viewed in the
debugger. When I write the variable out to Excel using the following the
number gets truncated to two decimal places:

With ActiveWorkbook.Worksheets("Dump Area")
.Cells(RowNumber, 2) = AreaCounts

Anyone have any suggestions to fix this problem?

Thanks !

--
Ray

--

Dave Peterson


--

Dave Peterson


--

Dave Peterson

  #14   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Number variable loses format on write

The # sign means that the variable is declared as a double.

Dim Area_Summed as Double

would have the same effect.


Halray wrote:

Dave,

Thanks for trying to help. The fix was to use a variable declared with the
pound symbol on the end. I'm not sure why that symbol matters, but it
worked. I did the following:

With ActiveWorkbook.Worksheets("Dump Area")
.Cells(RowNumber, 3) = RetentionTime
area_summed# = AreaSum
.Cells(RowNumber, 2) = area_summed#
'output paraffin area counts to column-4
area# = AreaCounts
.Cells(RowNumber, 4) = area#
End With

--
Ray

"Dave Peterson" wrote:

None from me.

But you never said what the numbers were!

Halray wrote:

Dave,

I've been away, but now that I check what you say I do not have that option
checked. Any more ideas?
--
Ray

"Dave Peterson" wrote:

One more guess.

If the cell is formatted to show 2 decimals and you have
Tools|Options|calculation tab|precision as displayed checked, it could cause
what you describe.

With ActiveCell
.NumberFormat = "0.00"
.Value = "1234.1234"
MsgBox .Value
End With



Halray wrote:

Two decimal places are displayed in the formula bar. In the debugger the
varibale has four decimal places.

--
Ray

"Dave Peterson" wrote:

If you look in the formulabar, do you see all 4 decimals?

If yes, try widening the column.

If no, what value do you see in the debugger and what value do you see in the
formulabar?

Halray wrote:

Have have a varibale declared as a double, read a number into it from a file.
THe variable is indicated with four decimal places when viewed in the
debugger. When I write the variable out to Excel using the following the
number gets truncated to two decimal places:

With ActiveWorkbook.Worksheets("Dump Area")
.Cells(RowNumber, 2) = AreaCounts

Anyone have any suggestions to fix this problem?

Thanks !

--
Ray

--

Dave Peterson


--

Dave Peterson


--

Dave Peterson


--

Dave Peterson
  #15   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Number variable loses format on write

I had the varibale declared as: Dim AreaSum as double, so I'm confused as to
why one declaration works and the other doesn't. Do you think it has
anything to do with re-declarating (probably not the correct wording) the
variable and reassigning it the value just before writing it?

Thanks again for taking the time to look at my issue.


--
Ray


"Dave Peterson" wrote:

The # sign means that the variable is declared as a double.

Dim Area_Summed as Double

would have the same effect.


Halray wrote:

Dave,

Thanks for trying to help. The fix was to use a variable declared with the
pound symbol on the end. I'm not sure why that symbol matters, but it
worked. I did the following:

With ActiveWorkbook.Worksheets("Dump Area")
.Cells(RowNumber, 3) = RetentionTime
area_summed# = AreaSum
.Cells(RowNumber, 2) = area_summed#
'output paraffin area counts to column-4
area# = AreaCounts
.Cells(RowNumber, 4) = area#
End With

--
Ray

"Dave Peterson" wrote:

None from me.

But you never said what the numbers were!

Halray wrote:

Dave,

I've been away, but now that I check what you say I do not have that option
checked. Any more ideas?
--
Ray

"Dave Peterson" wrote:

One more guess.

If the cell is formatted to show 2 decimals and you have
Tools|Options|calculation tab|precision as displayed checked, it could cause
what you describe.

With ActiveCell
.NumberFormat = "0.00"
.Value = "1234.1234"
MsgBox .Value
End With



Halray wrote:

Two decimal places are displayed in the formula bar. In the debugger the
varibale has four decimal places.

--
Ray

"Dave Peterson" wrote:

If you look in the formulabar, do you see all 4 decimals?

If yes, try widening the column.

If no, what value do you see in the debugger and what value do you see in the
formulabar?

Halray wrote:

Have have a varibale declared as a double, read a number into it from a file.
THe variable is indicated with four decimal places when viewed in the
debugger. When I write the variable out to Excel using the following the
number gets truncated to two decimal places:

With ActiveWorkbook.Worksheets("Dump Area")
.Cells(RowNumber, 2) = AreaCounts

Anyone have any suggestions to fix this problem?

Thanks !

--
Ray

--

Dave Peterson


--

Dave Peterson


--

Dave Peterson


--

Dave Peterson



  #16   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Number variable loses format on write

I used your version of the variable declaration with the pound symbol on the
end instead of the DIM statement and my code now works. Do you know why?


Thanks for your help on this - really do appreciate it.


--
Ray


"Tom Ogilvy" wrote:

AreaCount# = 1234.5678
? typename(areacount)
Double
ActiveCell.Value = Areacount#
? ActiveCell.Value
1234.5678
? activeCell.Text
1234.568

--
Regards,
Tom Ogilvy

"Halray" wrote in message
...
Two decimal places are displayed in the formula bar. In the debugger the
varibale has four decimal places.

--
Ray


"Dave Peterson" wrote:

If you look in the formulabar, do you see all 4 decimals?

If yes, try widening the column.

If no, what value do you see in the debugger and what value do you see

in the
formulabar?

Halray wrote:

Have have a varibale declared as a double, read a number into it from

a file.
THe variable is indicated with four decimal places when viewed in the
debugger. When I write the variable out to Excel using the following

the
number gets truncated to two decimal places:

With ActiveWorkbook.Worksheets("Dump Area")
.Cells(RowNumber, 2) = AreaCounts

Anyone have any suggestions to fix this problem?

Thanks !

--
Ray

--

Dave Peterson




  #17   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Number variable loses format on write

Maybe it was the mixture of variables. You could post your code (AND THE
NUMBERS USED) if you want.

Halray wrote:

I had the varibale declared as: Dim AreaSum as double, so I'm confused as to
why one declaration works and the other doesn't. Do you think it has
anything to do with re-declarating (probably not the correct wording) the
variable and reassigning it the value just before writing it?

Thanks again for taking the time to look at my issue.

--
Ray

"Dave Peterson" wrote:

The # sign means that the variable is declared as a double.

Dim Area_Summed as Double

would have the same effect.


Halray wrote:

Dave,

Thanks for trying to help. The fix was to use a variable declared with the
pound symbol on the end. I'm not sure why that symbol matters, but it
worked. I did the following:

With ActiveWorkbook.Worksheets("Dump Area")
.Cells(RowNumber, 3) = RetentionTime
area_summed# = AreaSum
.Cells(RowNumber, 2) = area_summed#
'output paraffin area counts to column-4
area# = AreaCounts
.Cells(RowNumber, 4) = area#
End With

--
Ray

"Dave Peterson" wrote:

None from me.

But you never said what the numbers were!

Halray wrote:

Dave,

I've been away, but now that I check what you say I do not have that option
checked. Any more ideas?
--
Ray

"Dave Peterson" wrote:

One more guess.

If the cell is formatted to show 2 decimals and you have
Tools|Options|calculation tab|precision as displayed checked, it could cause
what you describe.

With ActiveCell
.NumberFormat = "0.00"
.Value = "1234.1234"
MsgBox .Value
End With



Halray wrote:

Two decimal places are displayed in the formula bar. In the debugger the
varibale has four decimal places.

--
Ray

"Dave Peterson" wrote:

If you look in the formulabar, do you see all 4 decimals?

If yes, try widening the column.

If no, what value do you see in the debugger and what value do you see in the
formulabar?

Halray wrote:

Have have a varibale declared as a double, read a number into it from a file.
THe variable is indicated with four decimal places when viewed in the
debugger. When I write the variable out to Excel using the following the
number gets truncated to two decimal places:

With ActiveWorkbook.Worksheets("Dump Area")
.Cells(RowNumber, 2) = AreaCounts

Anyone have any suggestions to fix this problem?

Thanks !

--
Ray

--

Dave Peterson


--

Dave Peterson


--

Dave Peterson


--

Dave Peterson


--

Dave Peterson
  #18   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 129
Default Number variable loses format on write

Halray wrote:
I had the varibale declared as: Dim AreaSum as double, so I'm confused as to
why one declaration works and the other doesn't. Do you think it has
anything to do with re-declarating (probably not the correct wording) the
variable and reassigning it the value just before writing it?


TypeName function returns the type of a variable.
check your variable like this:

Dim AreaCounts As Double
MsgBox TypeName(AreaCounts)

'your code

MsgBox TypeName(AreaCounts)
.Cells(RowNumber, 2) = AreaCounts

I wonder if you have overlooked a typo or a mistake like
"Dim AreaCounts, AreaSum As Double", and then the Variant variable
has a Currency value.

--
HTH,

okaizawa
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
how to write 1234567890123456789 into a cell with number format Anila Excel Discussion (Misc queries) 3 February 13th 09 03:27 PM
number entered in cell loses trailing zeros in formula bar GKeyedr Excel Discussion (Misc queries) 5 January 10th 09 07:17 PM
variable number format in cell tina Excel Discussion (Misc queries) 2 November 7th 06 11:49 AM
webquery loses format of leading zero and to scientific Glen: Webquery format Excel Programming 3 August 11th 05 04:40 AM
Passing Number Format to a Variable ExcelMonkey[_133_] Excel Programming 13 June 7th 04 04:40 AM


All times are GMT +1. The time now is 06:13 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"