excel - Hide Cells Based on Dropdown, Keeps activating when not selected -


i created vba object hide , activate cells based on if particular value selected. contained within first column.

however, whenever continue edit other column once input information hides on me.

the full codes below. it's same thing repeated 5 times over. thanks!

private sub worksheet_change(byval target range)      if target.column = 1 , target.row = 3 , target.value = "cashback"          application.rows("4:7").select          application.selection.entirerow.hidden = false      else          application.rows("4:7").select          application.selection.entirerow.hidden = true      end if                if target.column = 1 , target.row = 3 , target.value = "content"          application.rows("8:25").select          application.selection.entirerow.hidden = false      else          application.rows("8:25").select          application.selection.entirerow.hidden = true      end if        if target.column = 1 , target.row = 3 , target.value = "price comparison"          application.rows("26:40").select          application.selection.entirerow.hidden = false      else          application.rows("26:40").select          application.selection.entirerow.hidden = true      end if            if target.column = 1 , target.row = 3 , target.value = "technology"          application.rows("41:52").select          application.selection.entirerow.hidden = false      else          application.rows("41:52").select          application.selection.entirerow.hidden = true      end if                if target.column = 1 , target.row = 3 , target.value = "vouchers"          application.rows("53:79").select          application.selection.entirerow.hidden = false      else          application.rows("53:79").select          application.selection.entirerow.hidden = true      end if                    if target.column = 1 , target.row = 3 , target.value = "all"          application.rows("3:200").select          application.selection.entirerow.hidden = false      end if                end sub

i refactored code bit make more efficient, easy understand / maintain, and, importantly, meet requirement.

option explicit  private sub worksheet_change(byval target range)  if not intersect(target, me.range("a3")) nothing , target.cells.count = 1      application.screenupdating = false      me.rows("4:200").entirerow.hidden = true      select case target.value          case = "cashback": me.rows("4:7").entirerow.hidden = false         case = "content": me.rows("8:25").entirerow.hidden = false         case = "price comparison": me.rows("26:40").entirerow.hidden = false          '... continue rest of scenarios ...          case = "all": me.rows("4:200").entirerow.hidden = false      end select  end if   end sub 

Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -