+ Reply to Thread
Results 1 to 14 of 14

Thread: Consolidate Repetitive Data

  1. #1
    Registered User
    Join Date
    01-08-2011
    Location
    KL,Malaysia
    MS-Off Ver
    Excel 2010
    Posts
    27

    Consolidate Repetitive Data

    Hi All

    I have a large set of Data that needs to be consolidated. Basically the data contains a large no of repetitive data and I need to consolidate them to analyze it further. Your assistance is much appreciated.

    I have attached the spreadsheet with a sample data and the outcome that I would like to obtain. Hope it all makes sense.

    Thanks

    Tamil
    Attached Files Attached Files
    Last edited by arasan25; 02-13-2012 at 09:53 PM.

  2. #2
    Forum Moderator arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    4,371

    Re: Consolidate Repetitive Data

    You can achieve the same through SUBTOTALS.
    Cheers,
    Arlette

    If I helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Registered User
    Join Date
    01-08-2011
    Location
    KL,Malaysia
    MS-Off Ver
    Excel 2010
    Posts
    27

    Re: Consolidate Repetitive Data

    Hi Arlette

    I tried, but it is not in the format of my "expected outcome" or I am not doing something right?

    Thanks

    Tamil

  4. #4
    Forum Moderator arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    4,371

    Re: Consolidate Repetitive Data

    As an after thought, i realised that sub totals wouldnt help you. I can provide you a small macro that will do your work.

    However, i have a question. I plan on checking 1 row with the next one to see if its same and then sum the values in column F. Which are the fields that i should check for similarity? Is it A to E & G or is just 1 field sufficient?
    Cheers,
    Arlette

    If I helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  5. #5
    Registered User
    Join Date
    01-08-2011
    Location
    KL,Malaysia
    MS-Off Ver
    Excel 2010
    Posts
    27

    Re: Consolidate Repetitive Data

    Hi Arlette

    It should be A to D & G.

    Thanks for your help.

    Tamil

  6. #6
    Forum Moderator arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    4,371

    Re: Consolidate Repetitive Data

    Use this code. The output will appear in Sheet 2. I didnt find any headers, you can put them in Sheet1 row2 and in Sheet2 row1.
    Option Explicit
    Dim lrow As Long
    Dim i As Long
    Dim rsum As Variant
    
    Sub consolidate_data()
    
    With Worksheets("Sheet1")
        lrow = .Range("A" & Rows.Count).End(xlUp).Row
        For i = 3 To lrow
            If .Range("A" & i).Value = .Range("A" & i + 1).Value And .Range("B" & i).Value = .Range("B" & i + 1).Value And _
            .Range("C" & i).Value = .Range("C" & i + 1).Value And .Range("D" & i).Value = .Range("D" & i + 1).Value And _
            .Range("G" & i).Value = .Range("G" & i + 1).Value Then
                rsum = rsum + .Range("F" & i).Value
            ElseIf .Range("A" & i).Value <> .Range("A" & i + 1).Value And .Range("B" & i).Value <> .Range("B" & i + 1).Value And _
            .Range("C" & i).Value <> .Range("C" & i + 1).Value And .Range("D" & i).Value <> .Range("D" & i + 1).Value And _
            .Range("G" & i).Value <> .Range("G" & i + 1).Value Then
                rsum = rsum + .Range("F" & i).Value
                .Range("A" & i & ":E" & i).Copy Worksheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
                Worksheets("Sheet2").Range("F" & Rows.Count).End(xlUp).Offset(1, 0).Value = rsum
                .Range("G" & i).Copy Worksheets("Sheet2").Range("G" & Rows.Count).End(xlUp).Offset(1, 0)
                rsum = 0
            End If
        Next i
    End With
    
    End Sub
    Cheers,
    Arlette

    If I helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  7. #7
    Registered User
    Join Date
    01-08-2011
    Location
    KL,Malaysia
    MS-Off Ver
    Excel 2010
    Posts
    27

    Re: Consolidate Repetitive Data

    Thanks Arlette!

    However I am not an expert in excel and my VBA skills certainly sucks!...........would you therefore be kind enough to incorporate this in the spreadsheet? Sorry for being a pain.

    Thanks

    Tamil

  8. #8
    Forum Moderator arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    4,371

    Re: Consolidate Repetitive Data

    I can guide you along. Press Alt+F11 on your file. It will open a code window. On the left hand side, you will see Microsoft Excel Objects. Right click on it and select Insert-> Module. Copy the above code into it. Go back to your main page. Go to View-> Macros and select the macro that is visible there.
    Run it.
    Cheers,
    Arlette

    If I helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  9. #9
    Registered User
    Join Date
    01-08-2011
    Location
    KL,Malaysia
    MS-Off Ver
    Excel 2010
    Posts
    27

    Re: Consolidate Repetitive Data

    Hi Arlette

    I think the code needs to be tweaked slightly. The similarity check should exclude column G. This should than work (I hope).

    Thanks

    Tamil

  10. #10
    Forum Moderator arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    4,371

    Re: Consolidate Repetitive Data

    Hey,

    You had asked to include column G, so i did. Find the revised code as below
    Option Explicit
    Dim lrow As Long
    Dim i As Long
    Dim rsum As Variant
    
    Sub consolidate_data()
    
    With Worksheets("Sheet1")
        lrow = .Range("A" & Rows.Count).End(xlUp).Row
        For i = 3 To lrow
            If .Range("A" & i).Value = .Range("A" & i + 1).Value And .Range("B" & i).Value = .Range("B" & i + 1).Value And _
            .Range("C" & i).Value = .Range("C" & i + 1).Value And .Range("D" & i).Value = .Range("D" & i + 1).Value Then
                rsum = rsum + .Range("F" & i).Value
            ElseIf .Range("A" & i).Value <> .Range("A" & i + 1).Value And .Range("B" & i).Value <> .Range("B" & i + 1).Value And _
            .Range("C" & i).Value <> .Range("C" & i + 1).Value And .Range("D" & i).Value <> .Range("D" & i + 1).Value Then
                rsum = rsum + .Range("F" & i).Value
                .Range("A" & i & ":E" & i).Copy Worksheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
                Worksheets("Sheet2").Range("F" & Rows.Count).End(xlUp).Offset(1, 0).Value = rsum
                .Range("G" & i).Copy Worksheets("Sheet2").Range("G" & Rows.Count).End(xlUp).Offset(1, 0)
                rsum = 0
            End If
        Next i
    End With
    
    End Sub
    Cheers,
    Arlette

    If I helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  11. #11
    Registered User
    Join Date
    01-08-2011
    Location
    KL,Malaysia
    MS-Off Ver
    Excel 2010
    Posts
    27

    Re: Consolidate Repetitive Data

    Hi Arlette,

    Yep it was my mistake. Looks like the nos are not there yet. Let me go through the errors in a bit more detail. Once I understand them I'll give you the right picture. Sorry for taking your time on this.

    Cheers

    Tamil

  12. #12
    Forum Moderator arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    4,371

    Re: Consolidate Repetitive Data

    Hey no, its never a waste of time. What do you mean the nos are not there yet? Are you getting any error?
    Cheers,
    Arlette

    If I helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  13. #13
    Registered User
    Join Date
    01-08-2011
    Location
    KL,Malaysia
    MS-Off Ver
    Excel 2010
    Posts
    27

    Re: Consolidate Repetitive Data

    Hi Arlette

    Hope you had a good weekend. I was pouring over the spreadsheet to see where the mistake is coming from. Managed to get an answer to the riddle (Problem was, there were too many variables and I have reduced it now). I have attached a revised spreadsheet for your perusal and you can see its a simpler one to the previous sheet. You only need to look at Column B for similarity and it should total Column D accordingly.

    Cheers

    Tamil
    Attached Files Attached Files

  14. #14
    Forum Moderator arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    4,371

    Re: Consolidate Repetitive Data

    Try this code -
    Option Explicit
    
    Dim lrow As Long
    Dim i As Long
    Dim rsum As Variant
    
    Sub consolidate_data()
    
    With Worksheets("Sheet1")
        lrow = .Range("A" & Rows.Count).End(xlUp).Row
        For i = 3 To lrow
            If .Range("B" & i).Value = .Range("B" & i + 1).Value Then
                rsum = rsum + .Range("D" & i).Value
            ElseIf .Range("B" & i).Value <> .Range("B" & i + 1).Value Then
                rsum = rsum + .Range("D" & i).Value
                .Range("A" & i & ":C" & i).Copy Worksheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
                Worksheets("Sheet2").Range("D" & Rows.Count).End(xlUp).Offset(1, 0).Value = rsum
                rsum = 0
            End If
        Next i
    End With
    
    End Sub
    Cheers,
    Arlette

    If I helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.2.0