Modifying Raw Data

ksiemens

New Member
Joined
Oct 21, 2012
Messages
15
Hi Everyone,

I'm working with a an excel report that is literally thousands of rows long (exported from accounting software). In order to effectively use the information, I need to sort the data. However, a very crucial piece of information (the unit number) will be lost if the report is sorted. Therefore, I need to modify the report prior to sorting it, and this is where the challenge begins....

Each row of the exported report contains sales data, such as invoice number, type of revenue, province, and amount (as shown below). This sales data always relates to a specific unit, which is shown as a group header above the respective sales data rows. In my simplified example (below), row 3-6 relate to sales information for unit1, while rows 9-12 relate to sales information for unit2 etc.

As you've probably already noticed, using the sort function will disconnect the unit numbers from the respective sales data. Therefore, I need to add the proper unit number to each related row (e.g. by adding the respective unit number into the next column, column E). However, due to the large amount of sales data as well as the extremely long list of unit numbers, performing this task manually is basically impossible. Does anybody have any ideas on how I could automatically add the correct unit numbers into the respective cells under column E?

Any ideas would be very much appreciated.

Thanks,
Katharina

ABCDE
1
2Unit 1
3Invoice 200Parts RevenueAB100.00
4Invoice 202Parts RevenueAB150.00
5Invoice 303Service RevenueBC300.00
6Invoice 207Warranty RevenueBC100.00
7
8Unit 2
9Inocie 55Service RevenueON500.00
10Invoice 302Service RevenueON600.00
11Invoice 210Warranty RevenueBC460.00
12Invoice 220Warranty RevenueBC300.00
13
14Unit 3
15Invoice 404Parts RevenueNS300.00
16Invoice 60Parts RevenueON800.00
17Invoice 88Warranty RevenueON400.00

<colgroup><col><col><col><col><col><col></colgroup><tbody>
</tbody>

<colgroup><col><col><col><col><col><col></colgroup><tbody>
</tbody>

<colgroup><col><col><col><col><col></colgroup><tbody>
</tbody>
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Does the whole follow that same format..

1. Is there always a blank row between Units?
2. Is the group header always in the same syntax... "Group x"..


If so.. I will give it a go.. :)
 
Upvote 0
Hi Apo,

Thanks for your reply. To answer your questions:

1. The data is quite messy and inconsistent, but it appears that there are always 4 blank rows between units (unless the sales volume was 0 for a unit, in which case the blank rows are increased to 5 or 6).
2. The group header is always the same syntax (with a changing unit number)

This is by far one of the worst data tables that I've ever worked with. If you have any ideas, I'd love to her them.

Cheers,
Katharina
 
Upvote 0
Hi..
This should do what you want... I added a CommandButton on the Sheet and ran the code from it..
I added heaps of comments within the code so you can see what is happening..
Code:
Private Sub CommandButton1_Click()
Dim LastRow As Long
Dim i As Long
Dim LastCell As Long


'Find the Last Row in Column A
LastRow = Sheets("Sheet1").Range("A65536").End(xlUp).Row


'Loop through the dataset
For i = 2 To LastRow


'Detect if cell in Column A is a Group Header
If InStr(1, Cells(i, 1).Value, "Unit") Then


'If so..  find the last cell in that Unit
LastCell = Sheets("Sheet1").Cells(i, 1).End(xlDown).Row


'Insert Group Header text into Column E for each row
Range(Cells(i, 1).Offset(1, 4), Cells(LastCell, 1).Offset(0, 4)) = Cells(i, 1).Value


'Cells(i, 1).ClearContents
End If
Next i
End Sub

If you want to remove the Group Header (Unit x) as it goes.. then Uncomment the following line..
Code:
'Cells(i, 1).ClearContents

Here's what it looks like after running the code.. don't worry about the asterix that are showing.. they just indicate a empty cell in Excel Jeanie .
(I tested it on 1000 rows.. took less than second to run)
Sheet1

*ABCDE
2Unit 1****
3Invoice 200Parts RevenueAB$100.00Unit 1
4Invoice 201Parts RevenueAB$150.00Unit 1
5Invoice 202Service RevenueBC$200.00Unit 1
6Invoice 203Warranty RevenueBC$250.00Unit 1
7*****
8Unit 2****
9Invoice 204Parts RevenueON$400.00Unit 2
10Invoice 205Parts RevenueON$450.00Unit 2
11Invoice 206Service RevenueBC$500.00Unit 2
12Invoice 207Warranty RevenueBC$550.00Unit 2
13Invoice 999Warranty RevenueBC$551.00Unit 2
14*****
15Unit 3****
16Invoice 208Parts RevenueON$700.00Unit 3
17Invoice 209Parts RevenueON$750.00Unit 3
18Invoice 210Service RevenueNS$800.00Unit 3
19Invoice 211Warranty RevenueBC$850.00Unit 3

<tbody>
</tbody>

Excel tables to the web - Excel Jeanie Html 4
 
Upvote 0

Forum statistics

Threads
1,215,420
Messages
6,124,803
Members
449,190
Latest member
cindykay

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top