LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default VBA sum - doesn't work with only one value.

Hi there, please can anyone help. Have some VBA calculating a sum from
values in column E. Got the code from this google group, and have just
about worked out how it works. However, I don't know how to adapt it
so that it does a sum even if there is only one value to sum. I
pressume it is something to do with how the range is calculated. This
is what I've got.

lr = Cells(Rows.Count, "c").End(xlUp).Row
e1 = Cells(1, "c").End(xlDown).Row

Do Until e1 = lr
e2 = Cells(e1, "c").End(xlDown).Row

Set myrange = Range(Cells(e1, "e"), Cells(e2, "e"))
Cells(e1 - 1, "c") = Application.sum(myrange)

e1 = Cells(e2, "c").End(xlDown).Row
Loop

this is what the data looks like after the macro has been run.

A B C D E

0 b333333 141.88 20/06/2006
1 b333333 125001 1 28.49
1 b333333 125003 1 37.89
1 b333333 125005 1 75.50
0 b222222 108.12 20/06/2006
1 b222222 125007 1 88.34
0 B444444 20/06/2006
1 B444444 125009 1 19.78
1 B444444 039001 1 2.77

I think it should calculate from the bottom value until there is a
blankcell and then offset the total into column C in the row above, but
it falls over if there is a single value to calculate. It has also
missed the bottom value off this calculation, but all works perfectly
if there is more than one value to sum.

I would be gratefull for any suggestions. Thanks in advance, BevJ

 
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 to update a column in a work based on another work sheet WickerMan New Users to Excel 1 December 4th 09 12:58 PM
how can i automatically generate work order numbers from work orde rob h Excel Discussion (Misc queries) 1 July 13th 09 07:59 PM
flash object dont work in my excel work sheet Nitn Excel Discussion (Misc queries) 0 July 4th 09 08:00 AM
Counting dates in multiple work sheets and work books Savage Excel Discussion (Misc queries) 0 December 19th 05 11:41 PM
Is there away to keep "auto save" from jumping to the first work sheet in the work book? Marc New Users to Excel 2 April 21st 05 01:27 AM


All times are GMT +1. The time now is 09:54 AM.

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

About Us

"It's about Microsoft Excel"