Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Convert a report with sub groups to a list

Posted on 2014-03-18
3
Medium Priority
?
182 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
[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
  • 2
3 Comments
 
LVL 39

Accepted Solution

by:
nutsch earned 2000 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

This article describes a serious pitfall that can happen when deleting shapes using VBA.
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

721 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