hide and unhide rows - based on one cell value

cacahuatitaCH

New Member
Joined
Jan 8, 2021
Messages
12
Office Version
  1. 365
Platform
  1. Windows
I am trying to make a code that will:
  • Check if value on B2 is "Cup" or "Glass"
  • Check if a specific set of rows is hidden (based on the value of B2)
  • Hide the set of rows if it is hidden
  • Unhide the set of rows if it is hidden
but all I have is the code to hide the rows... I've been trying to make it happen, based on IFs, but I haven't slept enough

I would be eternally grateful if someone would help out. I understand I am asking for basically the whole thing, but I have erased so many attempts I lost hope.

VBA Code:
'[I]Cup[/I]
    Rows("64:83,103:120,121:124,147:172,173:178,179:181,217:242,243:248,249:251,286:317,318:327,328:330,394:412,413:415,439:464,465:468,500:524,525:528,529:531,563:584,585:588,615:635,636:638,663:686").Select
    Selection.EntireRow.Hidden = True

'[I]Glass[/I]
    Rows("84:102,125:142,143:146,182:207,208:213,214:216,252:276,277:282,283:285,331:365,366:371,372:375,416:435,436:438,469:495,496:499,532:555,556:559,560:562,589:610,611:614,639:659,660:662,687:707").Select
    Selection.EntireRow.Hidden = True
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
VBA Code:
Public Sub HdUHd()
    Cells.EntireRow.Hidden = False
    If [B2] = "Cup" Or Range("B2") = "Glass" Then
    Range("64:83,103:120,121:124,147:172,173:178,179:181,217:242,243:248,249:251,286:317,318:327,328:330,394:412,413:415,439:464,465:468,500:524,525:528,529:531,563:584,585:588,615:635,636:638,663:686").EntireRow.Hidden = True
    Range("84:102,125:142,143:146,182:207,208:213,214:216,252:276,277:282,283:285,331:365,366:371,372:375,416:435,436:438,469:495,496:499,532:555,556:559,560:562,589:610,611:614,639:659,660:662,687:707").EntireRow.Hidden = True
    Else
    Range("64:83,103:120,121:124,147:172,173:178,179:181,217:242,243:248,249:251,286:317,318:327,328:330,394:412,413:415,439:464,465:468,500:524,525:528,529:531,563:584,585:588,615:635,636:638,663:686").EntireRow.Hidden = False
    Range("84:102,125:142,143:146,182:207,208:213,214:216,252:276,277:282,283:285,331:365,366:371,372:375,416:435,436:438,469:495,496:499,532:555,556:559,560:562,589:610,611:614,639:659,660:662,687:707").EntireRow.Hidden = False
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,824
Members
449,050
Latest member
Bradel

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
Back
Top