excel vba - Group rows by value -


how programmatically group following data values in column b?

note, there random values in columns a , c.

enter image description here

like this:

enter image description here --> enter image description here

try this

sub demo()     dim r range     dim v variant     dim long, j long      activesheet         on error resume next         ' expand groups on sheet         .outline.showlevels rowlevels:=8         ' remove existing groups         .rows.ungroup         on error goto 0         set r = .range("b1", .cells(.rows.count, 2).end(xlup))     end      r         'identify common groups in column b         j = 1         v = .cells(j, 1).value         = 2 .rows.count             if v <> .cells(i, 1)                 ' colum b changed, create group                 v = .cells(i, 1)                 if > j + 1                     .cells(j + 1, 1).resize(i - j - 1, 1).rows.group                 end if                 j =                 v = .cells(j, 1).value             end if         next         ' create last group         if > j + 1             .cells(j + 1, 1).resize(i - j - 1, 1).rows.group         end if         ' collapse groups         .parent.outline.showlevels rowlevels:=1     end end sub 

Comments

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -