#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,101
Default Sum

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Sum

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))

--


Gary


"Mike" wrote in message
...
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default Sum

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 & ")"


"Mike" wrote:

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

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



All times are GMT +1. The time now is 02:35 AM.

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"