Consulting

Results 1 to 7 of 7

Thread: Extract data from a table using two criteria variables

  1. #1
    VBAX Regular
    Joined
    May 2017
    Posts
    28
    Location

    Extract data from a table using two criteria variables

    Can someone tell me how in Excel, through formulas and/or filters or some other function, I can get the total dollar amount for each charge description for each address with table A being the original source data and table B being the extracted output as shown below. Thank you.

    Table A Data
    Address Charge Description Amount
    1303 W Clinton Dr Unit 109 Assessments 245
    1303 W Clinton Dr Unit 109 Lockbox Payment -245
    1303 W Clinton Dr Unit 109 Assessments 245
    1303 W Clinton Dr Unit 109 Late Fee 10
    1303 W Clinton Dr Unit 109 Late Interest 7.35
    1303 W Clinton Dr Unit 109 Lockbox Payment -245
    1303 W Clinton Dr Unit 109 Lockbox Payment -245
    1303 W Clinton Dr Unit 109 Assessments 245
    1303 W Clinton Dr Unit 109 Late Fee 10
    1303 W Clinton Dr Unit 109 Late Interest 3.94
    1303 W Clinton Dr Unit 110 Assessments 245
    1303 W Clinton Dr Unit 110 Lockbox Payment -245
    1303 W Clinton Dr Unit 110 Assessments 245
    1303 W Clinton Dr Unit 110 Lockbox Payment -245
    1303 W Clinton Dr Unit 110 Assessments 245
    1303 W Clinton Dr Unit 110 Late Fee 10
    1303 W Clinton Dr Unit 110 Late Interest 3.67
    1303 W Clinton Dr Unit 110 Lockbox Payment -245
    1303 W Clinton Dr Unit 110 Assessments 245
    1303 W Clinton Dr Unit 110 Lockbox Payment -245
    Table B Result
    Address Charge Description Amount
    1303 W Clinton Dr Unit 109 Assessments 735
    1303 W Clinton Dr Unit 109 Late Fee 20
    1303 W Clinton Dr Unit 109 Late Interest 11.29
    1303 W Clinton Dr Unit 109 Lockbox Payment -735
    1303 W Clinton Dr Unit 110 Assessments 980
    1303 W Clinton Dr Unit 110 Late Fee 10
    1303 W Clinton Dr Unit 110 Late Interest 3.67
    1303 W Clinton Dr Unit 110 Lockbox Payment -980

  2. #2
    VBAX Mentor 大灰狼1976's Avatar
    Joined
    Dec 2018
    Location
    SuZhou China
    Posts
    479
    Location
    Hi Bob789!
    Please refer to the Attachment.
    Attached Files Attached Files

  3. #3
    VBAX Regular
    Joined
    May 2017
    Posts
    28
    Location
    My system will not let me open spreadsheets like this. Can you put this information in the body of the email. Thank you.

  4. #4
    VBAX Mentor 大灰狼1976's Avatar
    Joined
    Dec 2018
    Location
    SuZhou China
    Posts
    479
    Location
    alright!
    sheet1.jpg
    sheet2.jpg

    commandbutton's code on sheet1
    Private Sub CommandButton1_Click()
    Dim arr, arr1, i&, d As Object, r&, s$
    arr = Sheets(1).[a1].CurrentRegion
    Set d = CreateObject("scripting.dictionary")
    ReDim arr1(1 To UBound(arr) - 1, 1 To UBound(arr))
    For i = 2 To UBound(arr)
      s = arr(i, 1) & "," & arr(i, 2)
      If Not d.exists(s) Then
        r = r + 1
        d(s) = r
        arr1(r, 1) = arr(i, 1)
        arr1(r, 2) = arr(i, 2)
      End If
      arr1(d(s), 3) = arr1(d(s), 3) + arr(i, 3)
    Next i
    With Sheets(2)
      .[a1].CurrentRegion.Offset(1).ClearContents
      .[a2].Resize(r, UBound(arr1)) = arr1
      .Activate
    End With
    MsgBox "Done!"
    End Sub

  5. #5
    In column C of Table B Result try:

    =SUMPRODUCT(($A$2:$A$21=H2)*($B$2:$B$21=I2)*$C$2:$C$21)

  6. #6
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,875
    A pivot table (a very basic/simple to set up one) can do this in a flash:
    2019-02-15_124412.jpgClick on the image to get a full size version.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  7. #7
    VBAX Regular
    Joined
    May 2017
    Posts
    28
    Location
    P45cal
    This is exactly what I need. FYI before you replied I concatenated the charge description to the address and used the sumif formula to get my data although the pivot table is much more versatile due to the ability to sort, query and filter. Thank you very much.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •