Solved

Excel VB-Add total price where date is the same

Posted on 2009-03-31
5
467 Views
Last Modified: 2012-05-11
Hi,

Please view the snapshot. I'm trying to add the total price (column "Z") where the date (i.e. serial date) is the same (column "X"). Then have the total for each date copied to Column "AA".

For instance, where column "X" = 39788 get the value of column "Z" for the given row. Then let Column "AA" row 2 = 39788 and Column "AB" row 2 = (total of column "Z" where "X" = 39788).

Hope that makes sense.

Thank you,
vkimura
excel-aggregate-total-where-date.png
0
Comment
Question by:Victor Kimura
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 50

Expert Comment

by:Dave Brett
ID: 24034868
can you pls post a sample file as opposed to a picture :)
Cheers
Dave
0
 

Author Comment

by:Victor Kimura
ID: 24035004
Hi brettdj,

Okay, here it is.
excel-aggregate-total-where-date.xls
0
 

Author Comment

by:Victor Kimura
ID: 24035112
I have this thus far where the commented numbers below the Dims are the serial dates. Everything is manually fixed. I'm thinking create an array with the serial dates and loop through them.

Sub MatchSerialDate2()
    Dim N As Long
    Dim payForDay As Long
    Dim totalPayForDay As Long
    ' 39788,39795,39786,39793,39787,39794,39785,39792
    For N = 2 To 3
        If Cells(N, 24) = 39788 Then
            payForDay = Cells(N, 19) 'pay for the given row
            totalPayForDay = Cells(2, 29) 'aggregate toal pay for the day
            Cells(2, 29) = payForDay + totalPayForDay
            Cells(2, 28) = 39788
        End If
    Next N
End Sub
0
 
LVL 59

Accepted Solution

by:
Saurabh Singh Teotia earned 500 total points
ID: 24035297
Vkumra,
Is this what you are looking for..?
Saurabh...
 

Sub MatchSerialDate2()
    Dim rng As Range, rng1 As Range, cell As Range, rng2 As Range, I As Long
    Set rng = Range("X2:X" & Cells(65536, "X").End(xlUp).Row)
    Set rng1 = Range("Z2:Z" & Cells(65536, "X").End(xlUp).Row)
    I = 2
    For Each cell In rng
        Set rng2 = Range("AA2:AA" & I)
        If cell.Value = cell.Offset(0, 1).Value And Application.WorksheetFunction.CountIf(rng2, cell.Value) = 0 Then
            Range("AA" & I).Value = cell.Value
            Range("AB" & I).Value = Application.WorksheetFunction.SumIf(rng, cell.Value, rng1)
            I = I + 1
        End If
    Next cell
 
End Sub

Open in new window

0
 

Author Closing Comment

by:Victor Kimura
ID: 31565111
Thank you, saurabh726. That works.
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we have discussed about the OS X EI Capitan and how to fix Wi-Fi issue in OS X El Capitan. We have explained how to delete system level preferences and create a new Wi-Fi location to resolve Wi-Fi issue.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question