PC Review


Reply
Thread Tools Rate Thread

add totals for each date

 
 
=?Utf-8?B?YW5kcmVzZzE5NzU=?=
Guest
Posts: n/a
 
      3rd Oct 2006
how can i create a macro that goes to column "A", insert a row after a date,
goes to column "C", get a total for that date in column "D" of the same row,
and continue the same procedure.

lets say:

column a b c d
row 1 09/01/2006 amex 1000
row 2 09/01/2006 visa 400
row 3 09/01/2006 visa 800
09/02/2006 visa 500
09/02/2006 amex 200

result should be:

column a b c d
row 1 09/01/2006 amex 1000
row 2 09/01/2006 visa 400
row 3 09/01/2006 visa 800
2200
09/02/2006 visa 500
09/02/2006 amex 200
700

and so on,

thanks a lot

 
Reply With Quote
 
 
 
 
Trevor Shuttleworth
Guest
Posts: n/a
 
      3rd Oct 2006
This will work if you have no header row, as indicated by your data:

Sub InsertTotals()
Dim LastRow As Long
Dim StartRow As Long
Dim EndRow As Long

Application.ScreenUpdating = False
LastRow = Range("A65536").End(xlUp).Row
For i = LastRow To 2 Step -1
If Range("A" & i).Value <> _
Range("A" & i - 1).Value Then
Range("A" & i).EntireRow.Insert
End If
Next
LastRow = Range("A65536").End(xlUp).Row
For i = 1 To LastRow + 1
If Range("A" & i).Value <> "" Then
If StartRow = 0 Then
StartRow = i
End If
Else
EndRow = i - 1
Range("D" & i).Formula = _
"=SUM(C" & StartRow & ":C" & EndRow & ")"
StartRow = 0
End If
Next
Application.ScreenUpdating = True
End Sub

And this will work if you do:

Sub InsertTotals()
Dim LastRow As Long
Dim StartRow As Long
Dim EndRow As Long

Application.ScreenUpdating = False
LastRow = Range("A65536").End(xlUp).Row
For i = LastRow To 3 Step -1
If Range("A" & i).Value <> _
Range("A" & i - 1).Value Then
Range("A" & i).EntireRow.Insert
End If
Next
LastRow = Range("A65536").End(xlUp).Row
For i = 2 To LastRow + 1
If Range("A" & i).Value <> "" Then
If StartRow = 0 Then
StartRow = i
End If
Else
EndRow = i - 1
Range("D" & i).Formula = _
"=SUM(C" & StartRow & ":C" & EndRow & ")"
StartRow = 0
End If
Next
Application.ScreenUpdating = True
End Sub

Regards

Trevor



"andresg1975" <(E-Mail Removed)> wrote in message
news:8F4E6F11-3BE2-4435-9889-(E-Mail Removed)...
> how can i create a macro that goes to column "A", insert a row after a
> date,
> goes to column "C", get a total for that date in column "D" of the same
> row,
> and continue the same procedure.
>
> lets say:
>
> column a b c d
> row 1 09/01/2006 amex 1000
> row 2 09/01/2006 visa 400
> row 3 09/01/2006 visa 800
> 09/02/2006 visa 500
> 09/02/2006 amex 200
>
> result should be:
>
> column a b c d
> row 1 09/01/2006 amex 1000
> row 2 09/01/2006 visa 400
> row 3 09/01/2006 visa 800
> 2200
> 09/02/2006 visa 500
> 09/02/2006 amex 200
> 700
>
> and so on,
>
> thanks a lot
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sum on totals by date with 1's and 0's =?Utf-8?B?ZWZhbmRhbmdv?= Microsoft Access Queries 4 13th Feb 2007 01:18 AM
Totals up to a Certain date JoeCL Microsoft Access Reports 1 15th Jan 2004 09:43 PM
Year to Date Totals in SQL pringb Microsoft Access Queries 2 20th Nov 2003 04:42 PM
Month to date and year to date totals Comcast News Groups Microsoft Access 1 27th Sep 2003 11:12 PM
Reports---adding Month-To-Date and Year-To-Date totals Patricia R. Turner Microsoft Access Reports 1 19th Sep 2003 06:23 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:39 AM.