data layout

Manexcel

Board Regular
Joined
Dec 28, 2015
Messages
127
Office Version
  1. 365
Platform
  1. Windows
I have a dataset that is grouped by level which I wish to re format onto another worksheet. An example is below:

Existing dataset

ColA ColB ColC
Level 1
Space
name1 group1 L1111
Space
Level 2
space
Name2 group2 C2222
Name3 group3 L3333
Name4 group4 L4444
space
Level 3
space
Name5 group5 L5555
Name6 group6 L6666
etc
Name20 group20 L2020

Is it possible to have a formula that will format / group the above dataset as follows (each group could have a maximum of say 20):

Required output

ColA ColB ColC ColD

Level1 name 1 group 1 L1111
Level2 name2 group2 C2222
name3 group3 L3333
name4 group4 L4444
Level3 name5 group5 C5555
name6 group6 L6666
name20 group20 L2020
etc

I thank you for time and understanding.
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Is this what you're after
Code:
Sub RealignData()

   Dim Rng As Range
   
   Columns(1).Insert
   With Columns(2)
      .Replace "Level", "=", xlPart, , False, , False, False
      For Each Rng In .SpecialCells(xlFormulas).Areas
         Rng.Cut Rng.Offset(2, -1)
      Next Rng
      .SpecialCells(xlBlanks).EntireRow.Delete
   End With
   Columns(1).Replace "=", "Level", xlPart, , False, , False, False
      
End Sub
 
Upvote 0
Many thanks for your quick response.

At present when i run the procedure i get a runtime error 1004.

The procedure creates col A and then gives the above message.

I have my dataset in sheet2 and am placing the procedure in sheet2

Any thoughts? Thank you again.
 
Upvote 0
First off the code needs to go in a standard module, rather than a sheet module.
Secondly are your levels called Level 1, Level 2 etc?
 
Upvote 0
ahhhh...

I defined the term "level" purely as an example name which could, in real life, be anyname (manager 1 or manager 2 or admin 1 or admin 3 and so on) that names are grouped under. I must be more specific with my requirement! Apologies.

Does the above assist you?

thank you for your continued patience.
 
Upvote 0
Does the above assist you?
Not really, it makes things a lot more complicated :(
Will the "levels" always have a blank row above & below?
Also will "level1" be in row 2, with a header in row 1?
 
Upvote 0
Last week you very kindly provided me with a procedure called "splitdata" which grouped data under a role. This is four columns and many rows.

name/role/group/number.

This grouped the source dataset under "role" in col B. and placed onto sheet2. The procedure produced spaces around each group.

An example of the source dataset that "splitdata" used is:

NameRolegroupNo.

<tbody>
</tbody>
name 1 Manager 1 group1 L1111
name 2 manager 1 group2 L2222
name 3 admin 1 group3 L33
etc.

The "splitdata" procedure grouped on Col B. The output produced was:

Col A Col B Col C
space
Manager 1
space
Name 1 group1 L1111
Name 2 group2 L2222
space
space
space

Admin 1
space
Name 3 group3 L33
space
space
space

etc

This is great and in use so thank you.

This request has an additional requirement for data layout taken either from the output of "splitdata" or the dataset source.

Required output

ColA ColB ColC ColD

R1 Manager1 name1 group1 L1111
R2 name2 group2 L2222
R3 Admin1 name3 group3 L33

etc

I trust the above makes a little more sense and clarification

Many thanks for your continued patience.
 
Upvote 0
If I've got this right, you started with


Excel 2013 32 bit
ABCDE
1Last NameFirst NameTitle 1Title 2Date
2SmithJohnSenior ManagerSM101/01/2017
3JonesAlanSenior ManagerSM102/02/2017
4BloggsFredManagerM101/01/2017
5BloggsGeorgeManagerM102/03/2017
6SmithMarySenior AdminSA102/02/2017
7SmithAlanAdministratorA101/06/2017
ID1


And you now want this


Excel 2013 32 bit
ABCD
10Title 1Last NameFirst NameDate
11Senior ManagerSmithJohn01/01/2017
12Senior ManagerJonesAlan02/02/2017
13ManagerBloggsFred01/01/2017
14ManagerBloggsGeorge02/03/2017
15Senior AdminSmithMary02/02/2017
16AdministratorSmithAlan01/06/2017
ID1


Is that right?
 
Upvote 0
So for each Title 1 e.g. Senior manager there is only one line for this title (A11) there is no Senior manager words in A12.


Senior manager Smith John 01/01/2017
Jones Alan 02/02/2017
Manager Bloggs Fred 01/01/2017
Bloggs george 02/03/2017
Senior admin Smith Mary 02/02/2017
Administrator Smith Alan 01/06/2017


Many thanks as always


****** id="cke_pastebin" style="position: absolute; top: 0px; width: 1px; height: 1px; overflow: hidden; left: -1000px;">ABCD10Title 1Last NameFirst NameDate11Senior ManagerSmithJohn01/01/201712Senior ManagerJonesAlan02/02/201713ManagerBloggsFred01/01/201714ManagerBloggsGeorge02/03/201715Senior AdminSmithMary02/02/201716AdministratorSmithAlan01/06/2017</body>
 
Upvote 0
Ok, how about
Code:
Sub ReorganiseData()

   Dim Cl As Range
   
   Columns(3).Cut
   Columns(1).Insert
   Columns(4).Delete
   With CreateObject("scripting.dictionary")
      For Each Cl In Range("A2", Range("A" & Rows.Count).End(xlUp))
         If Not .exists(Cl.Value) Then
            .Add Cl.Value, Nothing
         Else
            Cl.ClearContents
         End If
      Next Cl
   End With
   
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,336
Messages
6,124,330
Members
449,155
Latest member
ravioli44

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