excel - Hiding columns based upon cell value -


i not sure why code not working. intended recognise when press button (saying "hide1") , search through each column, row row, looking cells have value 1 once this, should change button "show 1". however, when run it, nothing happens.

here macro excel:

sub hide_columns()  dim integer dim j integer  = 3 j = 4  until = 26     until j = 54         activesheet.cells(i, j)             if .value = 1                 activesheet.columns(i).entirecolumn.hidden = true                 activesheet.shapes(application.caller).textframe.characters                     if .text = "show 1"                         .text = "hide 1"                     elseif .text = "hide 1"                         .text = "show 1"                     else                         msgbox ("vba has gone wrong.")                         exit sub                     end if                 end             end if         end         j = j + 1     loop     = + 1 loop  end sub 

you must re-structure inner loop:

sub hide_columns()  dim integer dim j integer  = 3  until = 26     j = 4     until j = 54         activesheet.cells(i, j)             if .value = 1             msgbox & vbcrlf & j                 activesheet.columns(i).entirecolumn.hidden = true                 activesheet.shapes(application.caller).textframe.characters                     if .text = "show 1"                         .text = "hide 1"                     elseif .text = "hide 1"                         .text = "show 1"                     else                         msgbox ("vba has gone wrong.")                         exit sub                     end if                 end             end if         end         j = j + 1     loop     = + 1 loop end sub 

explanation: first time through outer loop (for column a), row number, j, starts @ 4 , loops until it's 54. second time through outer loop (for column b), j still stuck @ 54, no rows in column b checked. fix this, reset j 4 each time move new column, shown above.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -