hide/show rows when cells in Column A are blank - based on data validation drop down list in a cell

Yodelayheewho

New Member
Joined
Jun 23, 2017
Messages
13
Hello,

I have searched the threads and cannot find the solution that fits my situation.

I have a worksheet with a data validation drop down menu in E3. This list is comprised of four types of services: Service 1, Service 2, Service 3, Service 4.

For each service, there is a unique set of tools, products and auxiliary items needed to complete the service.

Service 1 has 3 rows of tools, 3 rows of products and no auxiliary items
Service 2 has 3 rows of tools, 3 rows of products and no auxiliary items
Service 3 has 8 rows of tools, 5 rows of products and 9 rows of auxiliary items
Service 4 has 8 rows of tools, 5 rows of products and 9 rows of auxiliary items

I understand I can't accomplish what I need with a formula. So, I need to create a simple VBA (I'm a novice) that automatically hides/shows rows based on the drop down selection made in E3.

I apologize if I've not posted this correctly.

I appreciate any assistance you would provide.
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Sorry for my delayed response.
AAArqcthOGUHYQtN30hlK1Apa


The attached screen shots show Service 1 and Service 3. You really only need to focus on Column A since I removed proprietary information in the other columns. Notice that for Service 1 I had to put a note in the Auxiliary Section to let users know there are no Auxiliary items for Service 1, but Service 3 there is, which you can see in the second screen shot. What I would prefer is to have all rows hide if the cell in Column A is blank.
AAArqcthOGUHYQtN30hlK1Apa
 
Upvote 0
If you shared the actual mockup in excel it would have been easier but that's for next time.. :)

try this:

Code:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)

Dim rSelect As Range

Set rSelect = Intersect(Target, Range("E3"))
If Not rSelect Is Nothing Then
    Application.EnableEvents = False
        Select Case rSelect '1 line hide all rows in the section, 2nd line shows necesarry lines
            Case Is = "Service 1", "Service 2"
                'Next 2 lines show or hide tooling section
                Rows("6:13").EntireRow.Hidden = True
                Rows("6:8").EntireRow.Hidden = False
                'Next 2 lines show or hide product section
                Rows("18:22").EntireRow.Hidden = True
                Rows("18:20").EntireRow.Hidden = False
                'Next 2 lines show or hide aux section
                Rows("24:32").EntireRow.Hidden = True
            Case Is = "Service 3", "Service 4"
                'Next line show tooling section
                Rows("6:13").EntireRow.Hidden = False
                'Next line show product section
                Rows("18:22").EntireRow.Hidden = False
                'Next line show aux section
                Rows("24:32").EntireRow.Hidden = False
        End Select
    
End If

This VBA code needs to be copied onto the code page of the worksheet so not in a separate module.
 
Upvote 0

Forum statistics

Threads
1,215,579
Messages
6,125,646
Members
449,245
Latest member
PatrickL

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