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
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Code:
Public Sub HideUnhide9999()

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
Welcome to the Board!

A simple non-VBA solution would be just to use Filters. You can easily hide/unhide all rows equal to 9999 using Filters.
 
Last edited:
Upvote 0
Welcome to the Board!

A simple non-VBA solution would be just to use Filters. You can easily hide/unhide all rows equal to 9999 using Filters.

Hey!

Thanks for a lighting fast reply.

This sheet is supposed to be used by students of all majors, hence a single one time filtering won't work for this purpose. For example, if I choose a major "Entrepreneurship" in cell B14, then filter out all the 9999's, after choosing a different major, the same filtering still applies and has to be filtered again. Student's won't be doing filtering and it should be automated. Maybe there's a macro for re-filtering column A, when the major is changed?

-AK
 
Upvote 0
Hello!

Thank you for your time to help me out!

Just a quick question. I'm getting an error 13 "Type mismatch" while applying your code. Is there some basics I should know before or how this could be? I'll try again tomorrow after a possible reply, and will get back to you.

-AK
 
Upvote 0
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
 
Upvote 0
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

Did what you instructed. When I pasted your code in the immediate window I got a Runtime error '1004': Application-defined or object-defined error.
 
Upvote 0
Your initial code does in fact hide some rows, but when changing between majors, the rows still remains hiddes when they should be shown. If there's anything else you need for troubleshooting, let me know.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
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