Formatting Groups with VBA

sjk1193

New Member
Joined
Nov 12, 2018
Messages
29
I have the table below and I need to write a VBA script to change table 1 so that the data looks like table B and pastes the data in a new tab in the same workbook

The only distinguishing features between the rows is that one is bold and the others are not. The Bold is the overall group and the ones that are not bolded are holdings in the groups.
So I basically need it to list the group and the holdings side by side

1
[TABLE="width: 500"]
<tbody>[TR]
[TD]Name[/TD]
[TD]ID[/TD]
[/TR]
[TR]
[TD]ABC[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD] def[/TD]
[TD]2[/TD]
[/TR]
[TR]
[TD] qwe[/TD]
[TD]3[/TD]
[/TR]
[TR]
[TD]plm[/TD]
[TD]4[/TD]
[/TR]
[TR]
[TD] yui[/TD]
[TD]5[/TD]
[/TR]
[TR]
[TD]MNB[/TD]
[TD]6[/TD]
[/TR]
[TR]
[TD] ert[/TD]
[TD]7[/TD]
[/TR]
[TR]
[TD] lkj[/TD]
[TD]8[/TD]
[/TR]
[TR]
[TD] rtyu[/TD]
[TD]9[/TD]
[/TR]
</tbody>[/TABLE]


2
[TABLE="width: 500"]
<tbody>[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]ABC[/TD]
[TD]def[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]ABC[/TD]
[TD]qwe[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]plm[/TD]
[TD]yui[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]MNB[/TD]
[TD]ert[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]MNB[/TD]
[TD]lkj[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]MNB[/TD]
[TD]rtyu[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Try this for results starting "D1".
Code:
[COLOR="Navy"]Sub[/COLOR] MG15Nov27
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range, Temp [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String,[/COLOR] c [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
[COLOR="Navy"]Set[/COLOR] Rng = Range(Range("A2"), Range("A" & Rows.Count).End(xlUp))
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
    [COLOR="Navy"]If[/COLOR] Dn.Font.Bold = True [COLOR="Navy"]Then[/COLOR]
        Temp = Dn.Value
    [COLOR="Navy"]ElseIf[/COLOR] Temp <> "" [COLOR="Navy"]Then[/COLOR]
        c = c + 1
        Cells(c, 4) = Temp
        Cells(c, 4).Font.Bold = True
        Cells(c, 5) = Dn.Value
    [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR] Dn
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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