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
Last edited by arasan25; 02-13-2012 at 09:53 PM.
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]
Hi Arlette
I tried, but it is not in the format of my "expected outcome" or I am not doing something right?
Thanks
Tamil
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]
Hi Arlette
It should be A to D & G.
Thanks for your help.
Tamil
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]
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
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]
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
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]
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
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]
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
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]
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks