excel - hide column based on cell font color in a row vba -
i trying hide columns based on cell font color in first row. here want hide columns if cells in first row has black font color. now, dont want define range since data varies each week can have 10 columns week , 20 next week, , keep codes dynamic.
it looks vba codes went through (by pressing f8) without issues nothing happens. posted sample below along desire result.
sub test() dim range each in rows(1) if i.font.color = rgb(0, 0, 0) i.entirecolumn.hidden = true else i.entirecolumn.hidden = false end if next end sub
you need refer cells in range. , don't need if statement. try:
sub foo() dim c range each c in activesheet.usedrange.rows(1).cells c.entirecolumn.hidden = c.font.color = 0 next c end sub 

Comments
Post a Comment