Help - macro needed to iterate and copy

gojackets

New Member
Joined
Jul 9, 2015
Messages
1
Hello Everyone :)

Thanks for taking the time to view this post. I am familiar with macros but the language is sometimes confusing to me sometimes and I can get overwhelmed.

I have a raw data set that includes Categories and SubCategories.

***************************************
Here is an example in Table (given) Format:
[TABLE="class: grid, width: 200"]
<tbody>[TR]
[TD]Parent[/TD]
[TD]Sub1[/TD]
[TD]Sub2[/TD]
[TD]Sub3[/TD]
[/TR]
[TR]
[TD]Level II Services[/TD]
[TD]Hardware[/TD]
[TD]7401[/TD]
[TD]Cabinet[/TD]
[/TR]
[TR]
[TD]Level II Services[/TD]
[TD]Hardware[/TD]
[TD]7401[/TD]
[TD]Cabling[/TD]
[/TR]
[TR]
[TD]Level II Services[/TD]
[TD]Hardware[/TD]
[TD]7401[/TD]
[TD]Cash[/TD]
[/TR]
[TR]
[TD]Level II Services[/TD]
[TD]Hardware[/TD]
[TD]7402[/TD]
[TD]CD[/TD]
[/TR]
</tbody>[/TABLE]
*****************************
Same example Outlined (thought process):
Level II Services
  • Hardware
    • 7401
      • Cabinet
      • Cabling
      • Cash
    • 7402
      • CD
*****************************

I need to create general code that will iterate through the input / given table and separate the categories and subcategories in a waterfall-like pattern.

Visually:
If B2 != empty (or i,j != empty)
I need to copy the contents of A1 into A2, and move the contents of B2 to B3 (or i+1, j).

[TABLE="class: grid, width: 100"]
<tbody>[TR]
[TD]Level II Services[/TD]
[TD]Hardware[/TD]
[TD]7401[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

would look break out into
[TABLE="class: grid, width: 100"]
<tbody>[TR]
[TD]Level II Services[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Level II Services[/TD]
[TD]Hardware[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Level II Services[/TD]
[TD]Hardware[/TD]
[TD]7401[/TD]
[/TR]
</tbody>[/TABLE]

etc.

I then need to continue looping through the ith row and looking at next-right column (j+1) to check if it is != empty, and keep moving the contents until I reach the end of row i, and then I need to move onto row i+1​

Here is an example of what I need as an output:
[TABLE="class: grid, width: 100"]
<tbody>[TR]
[TD]Level II Services[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Level II Services[/TD]
[TD]Hardware[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Level II Services[/TD]
[TD]Hardware[/TD]
[TD]7401[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Level II Services[/TD]
[TD]Hardware[/TD]
[TD]7401[/TD]
[TD]Cabinet[/TD]
[/TR]
[TR]
[TD]Level II Services[/TD]
[TD]Hardware[/TD]
[TD]7401[/TD]
[TD]Cabling[/TD]
[/TR]
[TR]
[TD]Level II Services[/TD]
[TD]Hardware[/TD]
[TD]7401[/TD]
[TD]Cash[/TD]
[/TR]
[TR]
[TD]Level II Services[/TD]
[TD]Hardware[/TD]
[TD]7402[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Level II Services[/TD]
[TD]Hardware[/TD]
[TD]7402[/TD]
[TD]CD[/TD]
[/TR]
</tbody>[/TABLE]


Alternate way of looking at it:
Copying row i and pasting on row i+1, (i,j+1)


Help? Creating a new sheet (input: sheet1, output: sheet2) is fine :)
 
Last edited:

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

Forum statistics

Threads
1,223,236
Messages
6,170,906
Members
452,366
Latest member
TePunaBloke

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