excel - VBA: How to hide filtered (Spliced) Columns? -


i'm trying implement vba code hides columns "unnecessary" chosen filter.

i using slicers ease filtering table each subset has different information (data entries) in them.

eg. filtering type have data in columns e & f, while type b has data in e , g etc.

now wish to, @ given moment, show columns have data in them, make dataset more user-friendly.

i working on code:

private sub worksheet_change(byval target range)     dim c long     dim n long     application.screenupdating = false     n = rows(2).find(what:="*", searchdirection:=xlprevious).column     c = 3 n         cells(3, c).entirecolumn.hidden = (application.counta(columns(c)) < 2)     next c     application.screenupdating = true end sub 

as may notice, not hide columns based on "active filter" slicer, nor trigger on changing filter (eg choosing type b rather type in slicer)

sub hideempty() dim long dim lastcol long dim lastrow long lastcol = cells(1, columns.count).end(xltoleft).column 'if has fixed number of columns, _                                                         can replace lastcol = 5, example. _                                                         number 1 row headers = 1 lastcol     lastrow = cells(rows.count, i).end(xlup).row     if lastrow <= 1 '1 considering every column has header, regardless of having data. _                             if there no headers, replace 0         columns(i).entirecolumn.hidden = true     else 'this show columns hidden if have data         columns(i).entirecolumn.hidden = false     end if next end sub 

Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -