Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 504
Default Summing rounds answer to

I have a spreadsheet where each column in the spreadsheet from column 2 to
column 22 can be a record. Column 1 contains row headers. I can have from 1
to 21 records depending on the needs of the user. I need to be able to sum
each row and place that value into a column 1 column past the last record
column. I do this using the following code:

curRow = 40
maxRow = 51

'The following looping structure sums the values from the first column to
the last
'filled column, then puts the resulting value on the last column plus 1

Do While curRow <= maxRow

Set sumrng = Range(Cells(curRow, 2), Cells(curRow, numrec))
SumItemWt = Application.WorksheetFunction.Sum(sumrng)
Worksheets(1).Cells(curRow, numrec + 1).Value2 = SumItemWt

curRow = curRow + 1

Loop

When this code runs the value plced into the column numrec+1 is rounded up
to the nearest whole number. The cell is set as a number with 2 decimal
places. Instead of something like 4.76 I get 5.00.

Why?

If I place the standard cell formula manually into the spreasheet I get the
correct result. Why not with this code?

Any help will be greatly appreciated!

Kevin

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Summing rounds answer to

Do you have
Dim SumItemWt as Long
or
Dim SumItemWt as Integer

If so, that's your huckleberry.

Declare it as single or double.

--
Regards,
Tom Ogilvy

"Kevin" wrote in message
...
I have a spreadsheet where each column in the spreadsheet from column 2 to
column 22 can be a record. Column 1 contains row headers. I can have from

1
to 21 records depending on the needs of the user. I need to be able to sum
each row and place that value into a column 1 column past the last record
column. I do this using the following code:

curRow = 40
maxRow = 51

'The following looping structure sums the values from the first column to
the last
'filled column, then puts the resulting value on the last column plus 1

Do While curRow <= maxRow

Set sumrng = Range(Cells(curRow, 2), Cells(curRow, numrec))
SumItemWt = Application.WorksheetFunction.Sum(sumrng)
Worksheets(1).Cells(curRow, numrec + 1).Value2 = SumItemWt

curRow = curRow + 1

Loop

When this code runs the value plced into the column numrec+1 is rounded up
to the nearest whole number. The cell is set as a number with 2 decimal
places. Instead of something like 4.76 I get 5.00.

Why?

If I place the standard cell formula manually into the spreasheet I get

the
correct result. Why not with this code?

Any help will be greatly appreciated!

Kevin



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 504
Default Summing rounds answer to

Tom,

Imagine my right palm smakking my forhead and me saying ... DuuuuuH

That is my problem. I an a dummy!

Thanks!

Kevin

"Tom Ogilvy" wrote:

Do you have
Dim SumItemWt as Long
or
Dim SumItemWt as Integer

If so, that's your huckleberry.

Declare it as single or double.

--
Regards,
Tom Ogilvy

"Kevin" wrote in message
...
I have a spreadsheet where each column in the spreadsheet from column 2 to
column 22 can be a record. Column 1 contains row headers. I can have from

1
to 21 records depending on the needs of the user. I need to be able to sum
each row and place that value into a column 1 column past the last record
column. I do this using the following code:

curRow = 40
maxRow = 51

'The following looping structure sums the values from the first column to
the last
'filled column, then puts the resulting value on the last column plus 1

Do While curRow <= maxRow

Set sumrng = Range(Cells(curRow, 2), Cells(curRow, numrec))
SumItemWt = Application.WorksheetFunction.Sum(sumrng)
Worksheets(1).Cells(curRow, numrec + 1).Value2 = SumItemWt

curRow = curRow + 1

Loop

When this code runs the value plced into the column numrec+1 is rounded up
to the nearest whole number. The cell is set as a number with 2 decimal
places. Instead of something like 4.76 I get 5.00.

Why?

If I place the standard cell formula manually into the spreasheet I get

the
correct result. Why not with this code?

Any help will be greatly appreciated!

Kevin




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
Excel 2002 always rounds up automatically Kent Excel Worksheet Functions 3 January 29th 10 05:23 AM
Rounds the large numeric value Nilesh.Patel Excel Discussion (Misc queries) 2 January 28th 10 01:13 AM
formula needed that rounds to 99 cents jwbuyer Excel Worksheet Functions 4 January 30th 09 12:04 AM
Round function that rounds down if 5 Mikus Excel Worksheet Functions 5 August 29th 05 11:27 PM
How can set how a number rounds up in excel eric p Excel Worksheet Functions 1 October 28th 04 02:59 AM


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