Solved

Combine elements of a report to create a list

Posted on 2014-03-03
5
134 Views
Last Modified: 2014-03-05
Hi Experts,

A low-tech vendor sends me reports in Excel with the customer name and ID on a different line than the related records.  I want to run a procedure that puts the information identifying the customer on the same line as the invoice data.  In other words, I need to tag the invoice data with the customer ID from Col B and the Customer name from COL D.  The goal is to get a list that can be used for pivot tables or import.

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

Thanks for your help experts!
Carlisle-Sample-File.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
  • 3
  • 2
5 Comments
 
LVL 39

Accepted Solution

by:
nutsch earned 500 total points
ID: 39901528
Here's a macro that will do most of that for you. You only need to adjust a couple of the columns and you're all set:

Sub FixStuff()
Dim lLastRow As Long


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


lLastRow = Cells(Rows.Count, 1).End(xlUp).Row

Columns("A:C").Insert

With Cells(1, 4).CurrentRegion
    .AutoFilter
    .AutoFilter 1, "Customer"
    
    Range("A2:C" & lLastRow).SpecialCells(xlCellTypeVisible).FormulaR1C1 = "=RC[4]"
    Range("A2:C" & lLastRow).SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=R[-1]C"
    
    .AutoFilter
    
    Range("A2:C" & lLastRow).Value = Range("A2:C" & lLastRow).Value
    
    .AutoFilter 1, "Customer"
    
    .Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).EntireRow.Delete
    
    .AutoFilter
End With

Columns("B").Delete
Cells(1, 1) = "CUST"
Cells(1, 2) = "Customer Name"

With Application
    .ScreenUpdating = True
    .EnableEvents = True
    .Calculation = xlCalculationAutomatic
    .DisplayAlerts = True
End With


End Sub

Open in new window


Thomas
0
 

Author Comment

by:thutchinson
ID: 39901936
Thomas,

That is fabulous.  Works great. There's some good code in here.  
How can I learn to do this?
0
 

Author Closing Comment

by:thutchinson
ID: 39901940
Thank you. Thank you.-TMH
0
 
LVL 39

Expert Comment

by:nutsch
ID: 39901955
You practice a lot. You can check out the Excel VBA for Dummies by John Walkenbach, hang around EE and start trying to answer questions, record some macros and look at the code you get (though it won't be very good code for sure).

You can also hang out at the following sites, as quoted from Brad Yundt:

"A person interested in Excel will find numerous solutions to standard problems on sites run by Chip Pearson http://www.cpearson.com/excel/topic.aspxhttp://www.cpearson.com/excel/topic.aspx, John Walkenbach http://spreadsheetpage.com/index.php/site/tips/, Jon Peltier http://peltiertech.com/, Debra Dalgleish http://contextures.com/tiptech.html, and Ron de Bruin http://www.rondebruin.nl/ "
0
 

Author Comment

by:thutchinson
ID: 39906361
Good tips.  Thanks again Thomas.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
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…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

622 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