Help! Alter macro to automatically hide/unhide

swhitesides

New Member
Joined
Apr 17, 2009
Messages
16
I have this macro that adjust lines accordingly to the # chosen in the drop down box (using data validation).

Private Sub Worksheet_Change(ByVal Target As Range)
Dim r As Long
If Not Intersect(Target, Range("d1")) Is Nothing Then
Range("A10:A1793").EntireRow.Hidden = True
r = Target.Value - 1
Range("A10,A11:A" & 11 + r).EntireRow.Hidden = False
Range("A26,A27:A" & 28 + r).EntireRow.Hidden = False
Range("A43,A44:A" & 45 + r).EntireRow.Hidden = False
Range("A60,A61:A" & 62 + r).EntireRow.Hidden = False
Range("A77,A78:A" & 79 + r).EntireRow.Hidden = False
Range("A94,A95:A" & 96 + r).EntireRow.Hidden = False
Range("A111,A112:A" & 113 + r).EntireRow.Hidden = False
Range("A128,A129:A" & 130 + r).EntireRow.Hidden = False
Range("A145,A146:A" & 147 + r).EntireRow.Hidden = False
Range("A162,A163:A" & 164 + r).EntireRow.Hidden = False
Range("A179,A180:A" & 181 + r).EntireRow.Hidden = False
Range("A196,A197:A" & 198 + r).EntireRow.Hidden = False
Range("A213,A214:A" & 215 + r).EntireRow.Hidden = False
Range("A230,A231:A" & 232 + r).EntireRow.Hidden = False
Range("A247,A248:A" & 249 + r).EntireRow.Hidden = False
Range("A264,A265:A" & 266 + r).EntireRow.Hidden = False
Range("A281,A282:A" & 283 + r).EntireRow.Hidden = False
Range("A298,A299:A" & 300 + r).EntireRow.Hidden = False
Range("A315,A316:A" & 317 + r).EntireRow.Hidden = False
Range("A332,A333:A" & 334 + r).EntireRow.Hidden = False
Range("A349,A350:A" & 351 + r).EntireRow.Hidden = False
Range("A366,A367:A" & 368 + r).EntireRow.Hidden = False
Range("A383,A384:A" & 385 + r).EntireRow.Hidden = False
Range("A400,A401:A" & 402 + r).EntireRow.Hidden = False
Range("A417,A418:A" & 419 + r).EntireRow.Hidden = False
Range("A434,A435:A" & 436 + r).EntireRow.Hidden = False
Range("A451,A452:A" & 453 + r).EntireRow.Hidden = False
Range("A468,A469:A" & 470 + r).EntireRow.Hidden = False
Range("A485,A486:A" & 487 + r).EntireRow.Hidden = False
Range("A502,A503:A" & 504 + r).EntireRow.Hidden = False
Range("A519,A520:A" & 521 + r).EntireRow.Hidden = False
Range("A536,A537:A" & 538 + r).EntireRow.Hidden = False
Range("A553,A554:A" & 555 + r).EntireRow.Hidden = False
Range("A570,A571:A" & 572 + r).EntireRow.Hidden = False
Range("A587,A588:A" & 589 + r).EntireRow.Hidden = False
Range("A604,A605:A" & 606 + r).EntireRow.Hidden = False
Range("A621,A622:A" & 623 + r).EntireRow.Hidden = False
Range("A638,A639:A" & 640 + r).EntireRow.Hidden = False
Range("A655,A656:A" & 657 + r).EntireRow.Hidden = False
Range("A672,A673:A" & 674 + r).EntireRow.Hidden = False
Range("A689,A690:A" & 691 + r).EntireRow.Hidden = False
Range("A706,A707:A" & 708 + r).EntireRow.Hidden = False
Range("A723,A724:A" & 725 + r).EntireRow.Hidden = False
Range("A740,A741:A" & 742 + r).EntireRow.Hidden = False
Range("A757,A758:A" & 759 + r).EntireRow.Hidden = False
Range("A774,A775:A" & 776 + r).EntireRow.Hidden = False
Range("A791,A792:A" & 793 + r).EntireRow.Hidden = False
Range("A808,A809:A" & 810 + r).EntireRow.Hidden = False
Range("A825,A826:A" & 827 + r).EntireRow.Hidden = False
Range("A842,A843:A" & 844 + r).EntireRow.Hidden = False
Range("A859,A860:A" & 861 + r).EntireRow.Hidden = False
Range("A876,A877:A" & 878 + r).EntireRow.Hidden = False
Range("A893,A894:A" & 895 + r).EntireRow.Hidden = False
Range("A910,A911:A" & 912 + r).EntireRow.Hidden = False
Range("A927,A928:A" & 929 + r).EntireRow.Hidden = False
Range("A944,A945:A" & 946 + r).EntireRow.Hidden = False
Range("A961,A962:A" & 963 + r).EntireRow.Hidden = False
Range("A978,A979:A" & 980 + r).EntireRow.Hidden = False
Range("A995,A996:A" & 997 + r).EntireRow.Hidden = False
Range("A1012,A1013:A" & 1014 + r).EntireRow.Hidden = False
Range("A1029,A1030:A" & 1031 + r).EntireRow.Hidden = False
Range("A1046,A1047:A" & 1048 + r).EntireRow.Hidden = False
Range("A1063,A1064:A" & 1065 + r).EntireRow.Hidden = False
Range("A1080,A1081:A" & 1082 + r).EntireRow.Hidden = False
Range("A1097,A1098:A" & 1099 + r).EntireRow.Hidden = False
Range("A1114,A1115:A" & 1116 + r).EntireRow.Hidden = False
Range("A1131,A1132:A" & 1133 + r).EntireRow.Hidden = False
Range("A1148,A1149:A" & 1150 + r).EntireRow.Hidden = False
Range("A1165,A1166:A" & 1167 + r).EntireRow.Hidden = False
Range("A1182,A1183:A" & 1184 + r).EntireRow.Hidden = False
Range("A1199,A1200:A" & 1201 + r).EntireRow.Hidden = False
Range("A1216,A1217:A" & 1218 + r).EntireRow.Hidden = False
Range("A1233,A1234:A" & 1235 + r).EntireRow.Hidden = False
Range("A1250,A1251:A" & 1252 + r).EntireRow.Hidden = False
Range("A1267,A1268:A" & 1267 + r).EntireRow.Hidden = False
Range("A1284,A1285:A" & 1286 + r).EntireRow.Hidden = False
Range("A1301,A1302:A" & 1303 + r).EntireRow.Hidden = False
Range("A1318,A1319:A" & 1320 + r).EntireRow.Hidden = False
Range("A1335,A1336:A" & 1337 + r).EntireRow.Hidden = False
Range("A1352,A1353:A" & 1354 + r).EntireRow.Hidden = False
Range("A1369,A1370:A" & 1371 + r).EntireRow.Hidden = False
Range("A1386,A1387:A" & 1388 + r).EntireRow.Hidden = False
Range("A1403,A1404:A" & 1405 + r).EntireRow.Hidden = False
Range("A1420,A1421:A" & 1422 + r).EntireRow.Hidden = False
Range("A1437,A1438:A" & 1439 + r).EntireRow.Hidden = False
Range("A1454,A1455:A" & 1456 + r).EntireRow.Hidden = False
Range("A1471,A1472:A" & 1473 + r).EntireRow.Hidden = False
Range("A1488,A1489:A" & 1490 + r).EntireRow.Hidden = False
Range("A1505,A1506:A" & 1507 + r).EntireRow.Hidden = False
Range("A1522,A1523:A" & 1524 + r).EntireRow.Hidden = False
Range("A1539,A1540:A" & 1541 + r).EntireRow.Hidden = False
Range("A1556,A1557:A" & 1558 + r).EntireRow.Hidden = False
Range("A1573,A1574:A" & 1575 + r).EntireRow.Hidden = False
Range("A1590,A1591:A" & 1592 + r).EntireRow.Hidden = False
Range("A1607,A1608:A" & 1609 + r).EntireRow.Hidden = False
Range("A1624,A1625:A" & 1626 + r).EntireRow.Hidden = False
Range("A1641,A1642:A" & 1643 + r).EntireRow.Hidden = False
Range("A1658,A1659:A" & 1660 + r).EntireRow.Hidden = False
Range("A1675,A1676:A" & 1677 + r).EntireRow.Hidden = False
Range("A1692,A1693:A" & 1694 + r).EntireRow.Hidden = False
Range("A1709,A1710:A" & 1711 + r).EntireRow.Hidden = False
Range("A1726,A1727:A" & 1728 + r).EntireRow.Hidden = False
Range("A1743,A1744:A" & 1745 + r).EntireRow.Hidden = False
Range("A1760,A1761:A" & 1762 + r).EntireRow.Hidden = False
Range("A1777,A1778:A" & 1779 + r).EntireRow.Hidden = False


End If
End Sub


It works great! Except...if the values in red (notice from the top, but should continue through the macro) = 0 then hide that indicated range. The values in red are a vlookup reference from a master sheet. When information is entered into the master sheet, making the red value no longer = 0, I need for the corresponding rows to be automatically made visible.

This is completely stumping me. Any assistance would be greatly appreciated! :)
 

Some videos you may like

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce

Watch MrExcel Video

Forum statistics

Threads
1,123,293
Messages
5,600,773
Members
414,405
Latest member
Zaurb

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top