excel - Hide & unhide columns on all sheets with If function VBA -


i trying hide/unhide specific columns on 1 sheet named vpl , hide/unhide different set of specific columns on remaining sheets in workbook.

here code i've got far it's working on sheet named vpl , not hiding columns on other sheets when looping through remaining sheets in workbook.

    sub hideandunhideproduct2()  'are sure want run macro, when run box popup , ask yes or no dim varresponse variant varresponse = msgbox("this hide/unhide product 2 on sheets, want continue", vbyesno, "selection") if varresponse <> vbyes exit sub  application.screenupdating = false  'hides/unhides product columns on sheets  if vpl.columns("l:n").hidden = true  'unhides specified columns on specified sheet vpl.columns("l:n").entirecolumn.hidden = false 'unhides selected colunms  'unhides columns on sheets except ones specified below  dim wsu worksheet each wsu in sheets if wsu.name <> "vpl" '<sheets skiped loop         'code looped below columns("l:m").entirecolumn.hidden = false 'unhides selected colunms     'end of code looped     end if next wsu  else  'hides specified columns on specified sheet vpl.columns("l:n").entirecolumn.hidden = true  'hides columns on sheets except ones specified below dim wsh worksheet each wsh in sheets if wsh.name <> "vpl" '<sheets skiped loop         'code looped below columns("l:m").entirecolumn.hidden = true 'hides selected columns     'end of code looped     end if next wsh end if application.screenupdating = true  end sub 

any appreciated not in vba

without sheet reference, code

columns("l:m").entercolumn.hidden = false 

will refer active sheet. since looping through multiple sheets, need reference sheet variable in for-loop, so

wsu.colunns("l:m").entercolumn.hidden = false 

similarly for

wsh.columns("l:m").entirecolumn.hidden = true 

Comments

Popular posts from this blog

gridview - Yii2 DataPorivider $totalSum for a column -

java - Suppress Jboss version details from HTTP error response -

Sass watch command compiles .scss files before full sftp upload -