Separating Table Rows Into Separate Tables Based On Cell Value

ackalbo

New Member
Joined
Mar 10, 2013
Messages
46
Hello everyone.


I've only recently started to get back into learning VBA after a little absence and with my first project I fear I may have bitten off more than I can chew.


I have multiple managers each responsible for multiple employees. The company pay the employees licensing requirements and once working, the company then deducts a certain amount from salaries until the licensing requirement has been paid back.


Weekly, the company manually provides a basic weekly breakdown to all Managers so they are aware of the payment history and outstanding balances of their respective employees. This is currently being done manually by exporting the report from Quicken to Excel Compatible Text file then opening the file into Excel 2010 and manually resizing columns, deleting irrelevant columns, sorting the employees by ID number into their respective manager (in ID order then date) and then sub-totalling each employee.


For Example:

I would like to go from this


Excel 2010
ABCDEFGH
1Cash Advances
2
311/26/2013 through 02/28/2015
4
5DateAccountNumDescriptionMemoCategoryAmount
6
7Gea-1,650.00
82/5/2015CashCrisGeaLicenseCash Advance-1,650.00
9Gemma-680
102/9/2015LPOP Cash6002GemmaLicenseCash Advance-1,200.00
112/19/2015LPOP Cash6002GemmaLicense Balance P680Cash Advance520
12Jocelyn-1,120.00
132/9/2015Cash6100JocelynLicenseCash Advance-1,250.00
142/19/2015LPOP Cash6100JocelynLicense Balance P1120Cash Advance130
15Laila-1,220.00
162/12/2015Cash6005LailaLicenseCash Advance-1,220.00
17Marettie-1,250.00
182/9/2015Cash6003MarettieLicenseCash Advance-1,250.00
19Marilyn-1,000.00
202/9/2015LPOP Cash6001MarilynLicenseCash Advance-1,650.00
212/19/2015LPOP Cash6001MarilynLicense Balance P1000Cash Advance650
22Monica-1,620.00
232/10/2015Cash2067MonicaLicenseCash Advance-1,620.00
24Pamela-1,420.00
251/17/2015Cash3071PamelaLicenseCash Advance-1,650.00
262/19/2015LPOP Cash3071PamelaLicense Balance P1420Cash Advance230
27Renalyn-1,280.00
282/8/2015Cash1036RenalynLicenseCash Advance-1,100.00
292/14/2015LPOP Cash1036RenalynNSOCash Advance-400
302/19/2015LPOP Cash1036RenalynLicense Balance P1280Cash Advance220
31Rose Ann-1,650.00
322/5/2015CashCrisRose AnnLicenseCash Advance-1,650.00
33Roshel-1,400.00
342/9/2015Cash6004RoshelLicenseCash Advance-1,650.00
352/19/2015LPOP Cash6004RoshelLicense Balance P1400Cash Advance250
36OVERALL TOTAL########

<tbody>
</tbody>
Cash Advances 19th February 201




To This:


Excel 2010
BCDEF
2DateNumNameMemoAmount
32/8/20151036RenalynLicense-1,100.00
42/14/20151036RenalynNSO-400
52/19/20151036RenalynLicense Balance P1280220
6Renalyn Total-1280
7
82/9/20156002GemmaLicense-1,200.00
92/19/20156002GemmaLicense Balance P680520
10Gemma Total-680
11
122/9/20156100JocelynLicense-1,250.00
132/19/20156100JocelynLicense Balance P1120130
14Jocelyn Total-1120
15
162/12/20156005LailaLicense-1,220.00
17Laila Total-1,220.00
18
192/9/20156003MarettieLicense-1,250.00
20Marettie Total-1,250.00
21
222/9/20156001MarilynLicense-1,650.00
232/19/20156001MarilynLicense Balance P1000650
24Marilyn Total-1000
25
262/9/20156004RoshelLicense-1,650.00
272/19/20156004RoshelLicense Balance P1400250
28Roshel Total-1400
29
30Grand Total-7950
31
32
33
34DateNumNameMemoAmount
352/5/2015CrisRose AnnLicense-1,650.00
36Rose Ann Total-1650
372/5/2015CrisGeaLicense-1,650.00
38Gea Total-1650
391/17/20153071PamelaLicense-1,650.00
402/19/20153071PamelaLicense Balance P1420230
41Pamela Total-1420
42
43Grand Total-4720
44
45DateNumNameMemoAmount
462/10/20152067MonicaLicense-1,620.00
47Monica Total-1620
48
49Grand Total-1620

<tbody>
</tbody>
Cash Advances 19th February 201




Each manager's employees are distinguished by their own unique number. For instance - Manager A's employees start at 2001, Manager B's employees start at 3001 etc.


I have managed to write the following VBA code to open the original text file, delete unnecessary columns and rows and resize:


Code:
Option Explicit

Sub CashAdvReport()


Dim LastRow As Integer
Dim RowNum As Integer


Workbooks.OpenText Filename:="C:\Users\BackupWindows7Ult\Desktop\Cash Advance Test.TXT", DataType:=xlDelimited, Tab:=True


LastRow = ActiveSheet.UsedRange.Row - 1 + ActiveSheet.UsedRange.Rows.Count


Columns(1).EntireColumn.Delete


For RowNum = 1 To LastRow
    If Cells(RowNum, 3).Value = "" Then
        Rows(RowNum).EntireRow.Delete
    End If
Next RowNum


Rows("1:2").EntireRow.Delete
Rows(2).EntireRow.Delete
Columns(2).EntireColumn.Delete
Columns(5).EntireColumn.Delete
Worksheets(1).Range("A:E").EntireColumn.AutoFit
Range("B1").Value = "ID"
Range("C1").Value = "Name"
Columns("A:E").Sort key1:=Range("B2"), order1:=xlAscending, Header:=xlYes


LastRow = ActiveSheet.UsedRange.Row - 1 + ActiveSheet.UsedRange.Rows.Count


Range("A1").Resize(, 5).Select
Selection.Font.Bold = True
Selection.Font.Italic = True
Selection.Interior.Color = RGB(156, 156, 156)
Range("A1:E1").HorizontalAlignment = xlCenter
Range("A1:E1").Copy Cells(LastRow + 3, 1)

End Sub

The above code gives me the following result


Excel 2010
ABCDE
1DateIDNameMemoAmount
22/8/20151036RenalynLicense-1,100.00
32/14/20151036RenalynNSO-400
42/19/20151036RenalynLicense Balance P1280220
52/10/20152067MonicaLicense-1,620.00
61/17/20153071PamelaLicense-1,650.00
72/19/20153071PamelaLicense Balance P1420230
82/9/20156001MarilynLicense-1,650.00
92/19/20156001MarilynLicense Balance P1000650
102/9/20156002GemmaLicense-1,200.00
112/19/20156002GemmaLicense Balance P680520
122/9/20156003MarettieLicense-1,250.00
132/9/20156004RoshelLicense-1,650.00
142/19/20156004RoshelLicense Balance P1400250
152/12/20156005LailaLicense-1,220.00
162/9/20156100JocelynLicense-1,250.00
172/19/20156100JocelynLicense Balance P1120130
182/5/2015CrisGeaLicense-1,650.00
192/5/2015CrisRose AnnLicense-1,650.00
20
21
22DateIDNameMemoAmount

<tbody>
</tbody>
Cash Advance Test




Now I've hit a brick wall I'm afraid - I can't work out (It may be beyond my experience) how to go through the above list and separate out employees according to there ID range and move them to a separate table for each manager (let alone sub-totaling each employee).


Any pointers or advice would be greatly received and appreciated please guys & gals.
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.

Forum statistics

Threads
1,215,093
Messages
6,123,069
Members
449,090
Latest member
fragment

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