Macro to show/hide rows based on data validation drop-down selection

littlejilly

Board Regular
Joined
Sep 8, 2011
Messages
168
good afternoon friends and happy memorial day for those of us stateside!

I am working to update a pricing calculator and would like to show/hide rows based on a number of 1 or more drop downs. For example, if cell D3 in the capture below is DiseaseExperience, then Row 9 (DiseaseExperience) should hide. Additionally, cells D:H of that same row should also clear from any prior selections.

1653946729906.png


There are a number of other intersecting conditions that might happen but I'm hoping is someone can start me on the code, I can adjust thereafter for the nested conditions. I'd very much like for the code to update on click.

Thanks!
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
right click on you sheet - view code.

paste this in.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

If Not Intersect(Target, Range("D6")) Is Nothing Then

    Rows("9:100").EntireRow.Hidden = False 'unhide all hidden rows
    For r = 9 To 100
        If Cells(r, "C") = Split([D6], "_")(0) Then
            Rows(r).EntireRow.Hidden = True
            Range("D" & r & ":H" & r).ClearContents
           End If
     Next r
End If

End Sub

let me know how it works.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,184
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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