Solved

Convert a report with sub groups to a list

Posted on 2014-03-18
3
176 Views
Last Modified: 2014-03-18
Hello Experts,

I receive large sales reports in Excel that I need to be able to convert to a list. The report is grouped by customer name and ID on a different line than the related records.  I want to run a procedure that extracts the customer name and puts it on the same line as the invoice data.  The goal is to get a list that can be used for pivot tables or import.

Here's the steps that I identified:
-Remove Titles
-Insert new COL A
-Extract Customer name from string
-Populate COL A with the Customer name associated with correct invoice records
-Delete empty rows, subtotals, and section headers
-Anything else that you see wrong.

Attached is a workbook with the bad data that I receive in one tab and the result I need in the other tab.

Thanks for your help experts!
-TH
Add-Customer-to-each-record.xlsx
0
Comment
Question by:thutchinson
  • 2
3 Comments
 
LVL 39

Accepted Solution

by:
nutsch earned 500 total points
ID: 39938153
Here is a macro that should do all that neatly:

Sub Macro2()
Dim rgData As Range
Dim lLastRow As Long, lRowLoop As Long

'turn off updates to speed up code execution
With Application
    .ScreenUpdating = False
    .EnableEvents = False
    .Calculation = xlCalculationManual
    .DisplayAlerts = False
End With


Rows("1:11").Delete Shift:=xlUp
lLastRow = Cells(Rows.Count, 1).End(xlUp).Row
Columns("A").Insert
    
[a1] = Mid([b1], 12)
Range("A2:A" & lLastRow).FormulaR1C1 = "=if(left(rc[1],8)=""Customer"",right(rc[1],len(rc[1])-11),R[-1]C)"
Range("A1:A" & lLastRow).Value = Range("A1:A" & lLastRow).Value
Rows("1").Delete Shift:=xlUp
[a1] = "Customer"
    
With Range("A1:O" & lLastRow)
    .AutoFilter
    .AutoFilter Field:=8, Criteria1:= _
        "=Plug Cost", Operator:=xlOr, Criteria2:="="
    .Offset(1).SpecialCells(xlCellTypeVisible).EntireRow.Delete
    .AutoFilter
    .Columns.AutoFit
End With
    
With Application
    .ScreenUpdating = True
    .EnableEvents = True
    .Calculation = xlCalculationAutomatic
    .DisplayAlerts = True
End With

End Sub

Open in new window


Thomas
0
 

Author Closing Comment

by:thutchinson
ID: 39938267
Hi Thomas,

Perfection, as usual Thomas. I really appreciate it!

Best,

Todd
0
 
LVL 39

Expert Comment

by:nutsch
ID: 39938302
Glad to help.

THomas
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

792 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