Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / February 2007

Tip: Looking for answers? Try searching our database.

Sum

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mike - 15 Feb 2007 04:17 GMT
I have a workbork that does a mdb query by Date Range. Different Date ranges
returns more or less data. I would like to have Column H to total up at end
of data. My Start of data is H5. Can someone give me some insight on how to
do this

Thanks Mike
Gary Keramidas - 15 Feb 2007 04:34 GMT
two ways

Option Explicit
Sub sum_column_H()
Dim lastrow As Long
Dim ws As Worksheet

Set ws = Worksheets("sheet1")
lastrow = Cells(Rows.Count, "H").End(xlUp).Row
ws.Range("H" & lastrow).Offset(1).Formula = "=sum(h5:h" & lastrow & ")"
End Sub

or if you want just the value use the line below instead
ws.Range("H" & lastrow).Offset(1).Value = Application.Sum(Range("h5:H" & _
    lastrow))

Signature

Gary

>I have a workbork that does a mdb query by Date Range. Different Date ranges
> returns more or less data. I would like to have Column H to total up at end
> of data. My Start of data is H5. Can someone give me some insight on how to
> do this
>
> Thanks Mike
JMB - 15 Feb 2007 04:43 GMT
Assuming there is nothing below your data in Column H, maybe:

Sub test2()
With Worksheets("Sheet1")
 If IsEmpty(.Cells(.Rows.Count, 8)) Then
  With .Cells(.Rows.Count, 8).End(xlUp)
   .Offset(1, 0).Formula = "=Sum($H$5:" & _
    .Address & ")"
  End With
 End If
End With
End Sub

Assuming there are no breaks in your data and H5 could vary, you might also
try substituting this into the above:

.Offset(1, 0).Formula = "=Sum(" & _
   .End(xlUp).Address & ":" & .Address & ")"

> I have a workbork that does a mdb query by Date Range. Different Date ranges
> returns more or less data. I would like to have Column H to total up at end
> of data. My Start of data is H5. Can someone give me some insight on how to
> do this
>
> Thanks Mike
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.