Sorting Category Hierachy

Sharid

Well-known Member
Joined
Apr 22, 2007
Messages
1,064
Office Version
  1. 2016
Platform
  1. Windows
Hi

I’m a really stuck, I have a category list in EXCEL. I have a 35 categories, each with sub categories and each sub categories has further sub categories, a total of 6 levels. The amount of data I have to input manually is in about 15164 lines, over 6 columns.

Level 1 = 35
Level 2 = 587
Level 3 = 4995
Level 4 = 7243
Level 5 = 2183
Level 6 = 121

I am really stuck on this one, So far I have been inputting them by hand and it is taking forever. Can this be done with a code. :confused:

In this EXAMPLE I have used ONLY 4 columns, code must run over 6 columns, as above Levels = Columns

Please ignore the box around the words, I copied and Pasted the information and it has created some boxes, only the text is important


I need it to go from this

ABCD
Comics & Magz

<tbody>
</tbody>
Accessories

<tbody>
</tbody>
Book Covers

<tbody>
</tbody>
Book Plates

<tbody>
</tbody>
Bookmarks

<tbody>
</tbody>
Collectable

<tbody>
</tbody>
Audio Books

<tbody>
</tbody>
Calendars

<tbody>
</tbody>
Children's & Young Adults

<tbody>
</tbody>
Children's Annuals

<tbody>
</tbody>
Fiction

<tbody>
</tbody>
Children's Fiction

<tbody>
</tbody>
Children's Picture Books

<tbody>
</tbody>
Comics Graphic Novels

<tbody>
</tbody>

<tbody>
</tbody>


To This - I have added more catagory items on this one to give you a better picture, I have also coloured the changes so it show better to what I am after.

ABCD
Comics & Magz
Comics & Magz
Accessories
Comics & MagzAccessories
Book Covers
Comics & MagzAccessories
Book Plates

<tbody>
</tbody>
Comics & MagzAccessories
Bookmarks
Comics & MagzCollectable
Comics & MagzAudio Books
Comics & MagzCalendars
Comics & MagzChildren's & Young AdultsChildren's Annuals
Comics & MagzChildren's & Young Adults
Fiction

<tbody>
</tbody>
Comics & MagzChildren's & Young Adults
Fiction

<tbody>
</tbody>
Children's Fiction
Comics & MagzChildren's & Young Adults
Fiction

<tbody>
</tbody>
Children's Picture Books
Comics & MagzChildren's & Young Adults
Fiction

<tbody>
</tbody>
Comics Graphic Novels
Cars
Cars
BMW
Cars
BMW
Red
Cars
BMWBlue
Cars
BMWBlack
Cars
BMWBlack
Manual
Cars
BMWBlack
Automatic
Cars
Audi
Cars
Audi
Red
Cars
AudiRed
Manual
Cars
AudiRed
Automatic
Van
VanRed

<tbody>
</tbody>

 
Last edited:

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Try this:-
Data assumed to start in "A1".
Code:
[COLOR="Navy"]Sub[/COLOR] MG27May40
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range, R [COLOR="Navy"]As[/COLOR] Range, Temp [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String,[/COLOR] Ac [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
[COLOR="Navy"]Set[/COLOR] Rng = Range(Range("A1"), Range("A" & Rows.Count).End(xlUp))

[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng.SpecialCells(xlCellTypeBlanks).Areas
Dn.Value = Dn(1).Offset(-1).Value
    [COLOR="Navy"]For[/COLOR] Ac = 1 To 5
        Temp = ""
        [COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] R [COLOR="Navy"]In[/COLOR] Dn.Offset(, Ac)
            [COLOR="Navy"]If[/COLOR] R.Value <> "" [COLOR="Navy"]Then[/COLOR] Temp = R.Value
                R.Value = Temp
        [COLOR="Navy"]Next[/COLOR] R
    [COLOR="Navy"]Next[/COLOR] Ac
[COLOR="Navy"]Next[/COLOR] Dn
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Last edited:
Upvote 0
MickG

This is super, one again you have saved my life.:ROFLMAO:
 
Upvote 0

Forum statistics

Threads
1,215,726
Messages
6,126,503
Members
449,316
Latest member
sravya

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