Hide/Unhide rows based on value on the first cell of the row

Akukorhonen

New Member
Joined
Jul 25, 2017
Messages
8
Hey all!

A newbie to VBA here. I've been trying to search for this online already but couldn't find anything to fit my needs.

Here's the case:

I have created a sheet for tracking courses for 5 majors in my university. Based on a cell value B14 (dropdown list for choosing your major), the column A values will change to either to the course code (IEM311 for example) or to 9999 (meaning the row should be hidden). I'd need a code to do this and it should work both ways, hide and unhide, since some rows will be visible only on certain majors, and so on.

Rows the should be hidden(9999)/shown(other) based on Column A value. The range is A29:A180

Thanks for any help!

Cheers,
Aku
 
When you get the error, Press Ctrl+G and type the following into the Immediate window:

Code:
? i
? Cells(i, 1).Value
? TypeName(Cells(i, 1).Value)

Each line will produce an output; paste the result here.

WBD

Hey again,

Here are the outputs for these lines:

? i
50


? Cells(i, 1).Value
Error 2042


? TypeName(Cells(i, 1).Value)
Error

How to proceed now?
 
Upvote 0

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
So cell A50 has an error - perhaps #N/A?. Maybe just ignore it like this:

Code:
Public Sub HideUnhide9999()


On Error Resume Next


Dim i As Long
For i = 29 To 180
    Cells(i, 1).EntireRow.Hidden = Cells(i, 1).Value = 9999
Next i


End Sub

WBD
 
Upvote 0
So cell A50 has an error - perhaps #N/A?. Maybe just ignore it like this:

Code:
Public Sub HideUnhide9999()


On Error Resume Next


Dim i As Long
For i = 29 To 180
    Cells(i, 1).EntireRow.Hidden = Cells(i, 1).Value = 9999
Next i


End Sub

WBD

Awesome! This works almost as I need to. Now it hides all the cells that needs to be hidden, but it also need to unhide and hide again everything when I change the major. Is there a loop I could use?
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,636
Latest member
laura12345

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