Converting employee records to a table (I think I need VBA code)

INN

Board Regular
Joined
Feb 3, 2021
Messages
128
Office Version
  1. 365
Platform
  1. Windows
Hello all

I have excel file like this one (Please click in the link below) , these are records for each employee (names are fake). For example Cell A11 has the employee number which 81710 and then the mployee Name then under that cell, from Cell A12 to Cell A22 these are info belong to the same emplyee. I want to create table like this (see below) for all employee in the file

1733329459946.png


The Excel file

Any help would be very much appreciated. Thank you
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
As far as I know do the following:
1. Go to home tab
2. Select a random cell in your “list”
3. In the “styles” group click on format as table. Follow the prompts and make your choice (e.g. “my table has headers”). Format as table does more than formatting: is “creates a table” - which is in fact a “ listobject”.

I hope this helps.
 
Upvote 0
Hi thanks for your help. That did not help. Here is an example of 2 records in that sheet

1733331183270.png


And there are like hundard of them, there is a space between these records so if I select one cell of a record and then try to format as a table that would format that record only as a table but that would help, I need to separate Name and Employee#, B14, B20, and B22 into columns for all employees. Thanks once again
 
Upvote 0
My apologies Christine(?): 1st time I could not open the excel in the link you provided (error messages on my iPad). Now I understand your problem and my suggestion was indeed not helpful.
I will further think about it and possibly try something. Do you have VBA knowledge/experience? Possibly that will be a way to the solution.
 
  • Like
Reactions: INN
Upvote 0
Thank you. I know a bit about VBA but not very good at it. I can run a VBA code. Thanks
 
Upvote 0
I also had trouble opening the link; I think the sheet is just too big, as it kept going unresponsive. When I got in, I copied the first 5 records and got the snippet below. One thing I noticed from those records, is that they aren't all the same length and don't all have the same "B" numbers. I'm trying to work it out with formulas in Office 365 (web) and those are the stumbling blocks.

Book1
A
1Year End Reporting Run ID: 0000029747 PRODUCTION
2
3Form data
4
5
6
7
8T4
9
10
1181710 Hylton , Andre David
1201 895788222RP0002 ON
13B14 58751.87
14B16 3296.93
15B18 975.27
16B19 1145.91
17B20 5392.07
18B22 7282.41
19B24 58751.87
20B26 58751.87
21B27 3296.93
22B44 1262.83
23
2441195 Wong , Sophy
2501 895788222RP0002 ON
26B14 118552.64
27B16 3867.50
28B18 1049.12
29B19 1232.68
30B20 13123.48
31B22 22559.30
32B24 63200.00
33B26 68500.00
34B27 3867.50
35B44 1662.76
36
3781713 Ramlochan , Clyde
3801 895788222RP0002 ON
39B14 143427.18
40B16 3867.50
41B18 1049.12
42B19 1232.78
43B20 14272.08
44B22 30871.29
45B24 63200.00
46B26 68500.00
47B27 3867.50
48B44 2461.51
49F85 29.04
50
5141197 Slegers , Karen
5201 895788222RP0002 ON
53B14 6635.85
54B16 394.83
55B18 110.16
56B19 129.44
57B20 690.13
58B24 6635.85
59B26 6635.85
60B27 394.83
61B44 95.87
62
6381714 Martyn , Sarah
6401 895788222RP0002 ON
65B14 129868.03
66B16 3867.50
67B18 1049.12
68B19 1232.72
69B20 14640.73
70B22 25394.54
71B24 63200.00
72B26 68500.00
73B27 3867.50
74B44 2231.26
75F85 29.04
Sheet1
 
  • Like
Reactions: INN
Upvote 0
Pictures are of little value as they cannot be manipulated. Please reload your sample using MrE's XL2BB add in
 
  • Like
Reactions: INN
Upvote 0
using a combination of Power Query and then exporting the cleaned up file to a Pivot Table, your file is attached at the following location.


Here is the Mcode for anyone interested. Because the file is very large, I will only keep it up for about a week. After
that, you can create your own pivot table from the power query arranged data.

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Filtered Rows" = Table.SelectRows(Source, each ([Column1] <> null)),
    #"Removed Top Rows" = Table.Skip(#"Filtered Rows",3),
    #"Added Custom" = Table.AddColumn(#"Removed Top Rows", "Custom", each if Text.Contains([Column1]," ON") then 1 else null),
    #"Filtered Rows1" = Table.SelectRows(#"Added Custom", each ([Custom] = null)),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows1",{"Custom"}),
    #"Cleaned Text" = Table.TransformColumns(#"Removed Columns",{{"Column1", Text.Clean, type text}}),
    #"Trimmed Text" = Table.TransformColumns(#"Cleaned Text",{{"Column1", Text.Trim, type text}}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Trimmed Text", "Column1", Splitter.SplitTextByEachDelimiter({" "}, QuoteStyle.Csv, false), {"Column1.1", "Column1.2"}),
    #"Filtered Rows2" = Table.SelectRows(#"Split Column by Delimiter", each true),
    #"Added Custom1" = Table.AddColumn(#"Filtered Rows2", "TEST", each try Type.Is(Text.InferNumberType(Text.From([Column1.1])), type number) otherwise false),
    #"Added Custom2" = Table.AddColumn(#"Added Custom1", "Employee", each if [TEST]= true then [Column1.1] else null),
    #"Filled Down" = Table.FillDown(#"Added Custom2",{"Employee"}),
    #"Added Custom3" = Table.AddColumn(#"Filled Down", "Name", each if [TEST]=true then [Column1.2] else null),
    #"Filled Down1" = Table.FillDown(#"Added Custom3",{"Name"}),
    #"Filtered Rows3" = Table.SelectRows(#"Filled Down1", each ([TEST] = false)),
    #"Removed Columns1" = Table.RemoveColumns(#"Filtered Rows3",{"TEST"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Removed Columns1",{{"Column1.2", type number}}),
    #"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"Column1.1", "Category"}, {"Column1.2", "Value"}})
in
    #"Renamed Columns"
 
Upvote 0
using a combination of Power Query and then exporting the cleaned up file to a Pivot Table, your file is attached at the following location.


Here is the Mcode for anyone interested. Because the file is very large, I will only keep it up for about a week. After
that, you can create your own pivot table from the power query arranged data.

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Filtered Rows" = Table.SelectRows(Source, each ([Column1] <> null)),
    #"Removed Top Rows" = Table.Skip(#"Filtered Rows",3),
    #"Added Custom" = Table.AddColumn(#"Removed Top Rows", "Custom", each if Text.Contains([Column1]," ON") then 1 else null),
    #"Filtered Rows1" = Table.SelectRows(#"Added Custom", each ([Custom] = null)),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows1",{"Custom"}),
    #"Cleaned Text" = Table.TransformColumns(#"Removed Columns",{{"Column1", Text.Clean, type text}}),
    #"Trimmed Text" = Table.TransformColumns(#"Cleaned Text",{{"Column1", Text.Trim, type text}}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Trimmed Text", "Column1", Splitter.SplitTextByEachDelimiter({" "}, QuoteStyle.Csv, false), {"Column1.1", "Column1.2"}),
    #"Filtered Rows2" = Table.SelectRows(#"Split Column by Delimiter", each true),
    #"Added Custom1" = Table.AddColumn(#"Filtered Rows2", "TEST", each try Type.Is(Text.InferNumberType(Text.From([Column1.1])), type number) otherwise false),
    #"Added Custom2" = Table.AddColumn(#"Added Custom1", "Employee", each if [TEST]= true then [Column1.1] else null),
    #"Filled Down" = Table.FillDown(#"Added Custom2",{"Employee"}),
    #"Added Custom3" = Table.AddColumn(#"Filled Down", "Name", each if [TEST]=true then [Column1.2] else null),
    #"Filled Down1" = Table.FillDown(#"Added Custom3",{"Name"}),
    #"Filtered Rows3" = Table.SelectRows(#"Filled Down1", each ([TEST] = false)),
    #"Removed Columns1" = Table.RemoveColumns(#"Filtered Rows3",{"TEST"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Removed Columns1",{{"Column1.2", type number}}),
    #"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"Column1.1", "Category"}, {"Column1.2", "Value"}})
in
    #"Renamed Columns"

Thank you so much for all your help. I appreciate all of you. Thanks again
 
Upvote 0
using a combination of Power Query and then exporting the cleaned up file to a Pivot Table, your file is attached at the following location.


Here is the Mcode for anyone interested. Because the file is very large, I will only keep it up for about a week. After
that, you can create your own pivot table from the power query arranged data.

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Filtered Rows" = Table.SelectRows(Source, each ([Column1] <> null)),
    #"Removed Top Rows" = Table.Skip(#"Filtered Rows",3),
    #"Added Custom" = Table.AddColumn(#"Removed Top Rows", "Custom", each if Text.Contains([Column1]," ON") then 1 else null),
    #"Filtered Rows1" = Table.SelectRows(#"Added Custom", each ([Custom] = null)),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows1",{"Custom"}),
    #"Cleaned Text" = Table.TransformColumns(#"Removed Columns",{{"Column1", Text.Clean, type text}}),
    #"Trimmed Text" = Table.TransformColumns(#"Cleaned Text",{{"Column1", Text.Trim, type text}}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Trimmed Text", "Column1", Splitter.SplitTextByEachDelimiter({" "}, QuoteStyle.Csv, false), {"Column1.1", "Column1.2"}),
    #"Filtered Rows2" = Table.SelectRows(#"Split Column by Delimiter", each true),
    #"Added Custom1" = Table.AddColumn(#"Filtered Rows2", "TEST", each try Type.Is(Text.InferNumberType(Text.From([Column1.1])), type number) otherwise false),
    #"Added Custom2" = Table.AddColumn(#"Added Custom1", "Employee", each if [TEST]= true then [Column1.1] else null),
    #"Filled Down" = Table.FillDown(#"Added Custom2",{"Employee"}),
    #"Added Custom3" = Table.AddColumn(#"Filled Down", "Name", each if [TEST]=true then [Column1.2] else null),
    #"Filled Down1" = Table.FillDown(#"Added Custom3",{"Name"}),
    #"Filtered Rows3" = Table.SelectRows(#"Filled Down1", each ([TEST] = false)),
    #"Removed Columns1" = Table.RemoveColumns(#"Filtered Rows3",{"TEST"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Removed Columns1",{{"Column1.2", type number}}),
    #"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"Column1.1", "Category"}, {"Column1.2", "Value"}})
in
    #"Renamed Columns"
I was thinking about a VBA-program, but this is a far more elegant solution!!
 
Upvote 0

Forum statistics

Threads
1,224,570
Messages
6,179,610
Members
452,931
Latest member
The Monk

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