Excel Unhide Row based on value in a range -
i know there many questions here hiding , unhiding rows in excel-vba can't seem code work...
i working on spreadsheet has month's totals listed on top. want sheet hide row of month's total doesn't appear in sheet.
for ex. if there no data in list january january totals row hidden. once puts data january in list row unhide.
i know script won't running @ times added "month reset" button run script , hide/unhide appropriate rows.
for reason, every time hit button, row disappears regardless of whether or not data in list below. wrote code january's row far:
private sub commandbutton1_click() sheets("master pipeline").select each cell in range("b16:b100") if cell.value = "january" range("a3").entirerow.hidden = false else range("a3").entirerow.hidden = true end if next end sub
cells a3:a14 have months listed totals in cells next them. rows 16:100 have list of data, column b has month.
please help...
thanks in advance,
lt
you can use following hide months missing in data range. note don't need (and shouldn't) write code each month. note finding value in range dramatically more efficient looping through data range.
have button call sub:
sub hidemissingmonths() dim ws worksheet dim months range dim data range dim cell range dim found range set ws = thisworkbook.sheets("master pipeline") set months = ws.range("a3:a14") set data = ws.range("b16:b100") application.screenupdating = false ' unhide months before begin months.entirerow.hidden = false each cell in months set found = data.find(what:=cell, lookin:=xlvalues) if found nothing cell.entirerow.hidden = true next cell application.screenupdating = true end sub
Comments
Post a Comment