Solved

How can i parse this data using VBA in excel? PART 2!

Posted on 2011-03-21
3
231 Views
Last Modified: 2012-06-22
The file shows 5 levels of product information product type, company, color, sub classification and product. Also imagine 100's of product types and 100's of months of data. It all follows the same basic layout throughout.

Beside the product's are monthly sales dollars and units sold. I'd like a flat list of this data for pivot use.

Side note - the file i'm working with has groupings that collapse this data, is there possibly a non vba way of getting a flat list? food for thought

Attached is a file and the code here shows how to get this task done properly with 3 levels of data. (Thanks nutsch)
Private Sub CleanUpAgain()
Dim lastRow As Long, i As Long 'define variables
application.ScreenUpdating = False 'disable ScreenUpdating to avoid screen flashes

lastRow = Cells(Rows.Count, "C").End(xlUp).Row 'get last row

With range("A6:B" & lastRow)
    .SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=R[-1]C"
    .Value = .Value
End With

Rows("5:6").Delete

Cells(4, 1) = "TYPE"
Cells(4, 2) = "COMPANY"
Cells(4, 3) = "PRODUCT"

With Cells(4, 1).CurrentRegion
    .AutoFilter Field:=3, Criteria1:="="
    .Offset(1).SpecialCells(xlCellTypeVisible).EntireRow.Delete
    .AutoFilter
End With

For i = 4 To Cells(4, Columns.Count).End(xlToLeft).Column
    Cells(3, i) = Left(Cells(4, i), Len(Cells(4, i)) - InStr(StrReverse(Cells(4, i)), " "))
    Cells(4, i) = Trim(Right(Cells(4, i), InStr(StrReverse(Cells(4, i)), " ")))
Next i

application.ScreenUpdating = True 'reenable ScreenUpdating
End Sub

Open in new window

Example2.xls
0
Comment
Question by:sanjangeorge
[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 500 total points
ID: 35185136
Here is a more flexible update for you

Private Sub CleanUpAgain()
Dim lastRow As Long, i As Long, lastCol As Long 'define variables
Application.ScreenUpdating = False 'disable ScreenUpdating to avoid screen flashes


lastCol = 5 'E is the 5th column
lastRow = Cells(Rows.Count, lastCol).End(xlUp).Row 'get last row

With Range(Cells(6, 1), Cells(lastRow, lastCol - 1))
    .SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=R[-1]C"
    .Value = .Value
End With

Rows("5:" & 5 + lastCol - 1).Delete

Cells(4, 1) = "TYPE"
Cells(4, 2) = "COMPANY"
Cells(4, 3) = "COLOR"
Cells(4, 4) = "SUBCLASS"
Cells(4, 5) = "PRODUCT"

With Cells(lastCol + 1, 1).CurrentRegion
    .AutoFilter Field:=lastCol, Criteria1:="="
    .Offset(1).SpecialCells(xlCellTypeVisible).EntireRow.Delete
    .AutoFilter
End With

For i = lastCol + 1 To Cells(4, Columns.Count).End(xlToLeft).Column
    Cells(3, i) = Left(Cells(4, i), Len(Cells(4, i)) - InStr(StrReverse(Cells(4, i)), " "))
    Cells(4, i) = Trim(Right(Cells(4, i), InStr(StrReverse(Cells(4, i)), " ")))
Next i

Application.ScreenUpdating = True 'reenable ScreenUpdating
End Sub

Open in new window


When you have a related question like that, use the "Ask a related question" link on the original question and the experts who helped you initially will be notified imedi
0
 

Author Comment

by:sanjangeorge
ID: 35193186
Thanks nutsch,

I tried to ask you in the previous thread but i guess you weren't notified
0
 
LVL 39

Expert Comment

by:nutsch
ID: 35215769
Glad to help.

Thomas
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

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,…
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

734 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