Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Having a moving Total

I have a worksheet that is linked to a query. When the query updates
the number of rows can either increase or decrease. At the bottom of
the last two columns I want a total for each column.

How can I make the totals move up and down the sheet so they are always
directly below the last row?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 983
Default Having a moving Total

To find the first empty row here is some easy code

Dim rngLastRow As Range

Set rngLastRow = Sheet1.Range("A65535").End(xlUp).Offset(1, 0)
rngLastRow.Select 'This line is optional and assumes you want to select the
row

I assume you can take it from here...

HTH

"Keith" wrote:

I have a worksheet that is linked to a query. When the query updates
the number of rows can either increase or decrease. At the bottom of
the last two columns I want a total for each column.

How can I make the totals move up and down the sheet so they are always
directly below the last row?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 212
Default Having a moving Total

Assuming there is only 1 Query Table in that sheet,
You can put below code in that sheet's
Worksheet_Change event procedu
Everytime the query is update, Wroksheet_Change event
for that sheet is fired and below code will do what you want.

Private Sub Worksheet_Change(ByVal Target As Range)
Dim myValue as Double, c
With Me.QueryTables(1).ResultRange
For Each c In .Columns(.Columns.Count)
If IsNumeric(c.Value) Then
myValue = myValue + c.Value
End If
Next c
Me.Cells(.Cells(.Rows.Count + 1, 1).Row, _
.Cells(1, .Columns.Count).Column).Value = myValue
myValue = 0
For Each c In .Columns(.Columns.Count - 1)
If IsNumeric(c.Value) Then
myValue = myValue + c.Value
End If
Next c
Me.Cells(.Cells(.Rows.Count + 1, 1).Row, _
.Cells(1, .Columns.Count - 1).Column).Value = myValue
End With
End Sub

Sharad

"Keith" wrote in message
...
I have a worksheet that is linked to a query. When the query updates the
number of rows can either increase or decrease. At the bottom of the last
two columns I want a total for each column.

How can I make the totals move up and down the sheet so they are always
directly below the last row?



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
moving informatiion from one sheet to a total sheet john Excel Discussion (Misc queries) 2 January 31st 08 10:17 PM
Pivot Tables moving "Total Columns" kanstrup New Users to Excel 1 August 27th 07 04:41 PM
Moving grand total columns in pivot table Fil Excel Discussion (Misc queries) 1 January 21st 07 04:54 PM
Using the OFFSET and COUNT functions to get a moving total Eduardo Excel Discussion (Misc queries) 2 November 1st 05 01:58 AM
Moving total snn Excel Worksheet Functions 1 March 13th 05 09:15 PM


All times are GMT +1. The time now is 07:02 PM.

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"