Solved

consolidate data by two criteria

Posted on 2014-10-15
6
104 Views
Last Modified: 2014-10-20
I need to create a consolidated table from a longer table.  The raw data is as attached.  I need to consolidate by code and date.  ie: numbers of hours per code per date.  A pivot table gives me the correct data but I need it in column format to feed into another workbook.
Thanks in advance.
Example1.xlsx
0
Comment
Question by:acdecal
[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
  • 4
  • 2
6 Comments
 
LVL 22

Expert Comment

by:Flyster
ID: 40382606
You can use SUMIFS. Place this formula in H4 and copy down:

=SUMIFS(C:C,A:A,F4,B:B,G4)

Flyster
0
 

Author Comment

by:acdecal
ID: 40382811
That would required me to have data in columns F & G to use as criteria.  I have over 5,000 rows of raw data that I need to consolidate by week and code.  I have wrote VBA code to do this but I'm afraid it will take a considerable amount of time to run.  I was hoping for an easier solution like using the consolidation function or subtotaling or getting the data from a pivot table.
0
 

Accepted Solution

by:
acdecal earned 0 total points
ID: 40382874
I used the code below:   I little clunky but it works.


Sub consolidate()
Dim D1 As String, D2 As String, C1 As String, C2 As String
Dim i As Long, MH As Long, j As Long



j = 1
For i = 2 To 600
 MH = Cells(i, 3).Value + MH
 C1 = Cells(i, 1).Value

 C2 = Cells(i + 1, 1).Value
If C2 = "" Then GoTo A:
If C1 = C2 Then

 D1 = Cells(i, 2).Value
 D2 = Cells(i + 1, 2).Value
If D1 = D2 Then


Else

Cells(j, 10).Value = C1
Cells(j, 11).Value = D1
Cells(j, 12).Value = MH
MH = 0
j = j + 1



End If
Else

Cells(j, 10).Value = C1
Cells(j, 11).Value = D1
Cells(j, 12).Value = MH
MH = 0
j = j + 1


End If
Next i
A:
Cells(j, 10).Value = C1
Cells(j, 11).Value = D1
Cells(j, 12).Value = MH

End Sub
0
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
LVL 22

Expert Comment

by:Flyster
ID: 40383521
Here’s one way to achieve the result you’re looking for. Concatenate column A & B with this formula:

=A2&" "&TEXT(B2,"mm/dd/yyyy")

Then go to the Data tab and select Subtotal. In the “At change in” dropdown select the new field.  In the “Add subtotal to” dropdown select Mhs. See attached.
Example1.xlsx
0
 

Author Comment

by:acdecal
ID: 40383528
That's a clever way of determining a unique item but would require me to un-concatenation to get it to the format I need. Thanks for your efforts!
0
 

Author Closing Comment

by:acdecal
ID: 40391555
As stated
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

710 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