Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How to trigger a Marco with a data validation selection Hey all. I am really ine

ID: 3570258 • Letter: H

Question

How to trigger a Marco with a data validation selection

Hey all. I am really inexperienced with VBA and Marcos, however I am trying to tackle a dynamic row graph based on the user selecting a product segment from a drop down data validation tool. The code below is what I have so far that will hide rows and unhide rows if I change the formulas in my chart areas, however when I choose a different product segment it doesn't trigger anything. Any ideas?? Thanks!

Private Sub Worksheet_Change(ByVal Target As Range)

    If Not Intersect(Target, Range("G39:G53")) Is Nothing Then

        Application.EnableEvents = False

        Dim r As Range

        For Each r In Intersect(Range("G39:G53"), Me.UsedRange)

            r.EntireRow.Hidden = (UCase(r.Value) = "")

        Next r

    End If

FallThrough:

    Application.EnableEvents = True:

End Sub

Explanation / Answer

Hi....

The code that you have shown is what is called and "event" macro, and goes into the codemodule of the worksheet. It will not show up in your list of macros since it takes an argument (the "(ByVal Target As Range)" part), and because it has Private in its declaration.

To do something when T36 changes as well::

Private Sub Worksheet_Change(ByVal Target As Range)

  Dim r As Range

If Not Intersect(Target, Range("G39:G53")) Is Nothing Then

        Application.EnableEvents = False

For Each r In Intersect(Range("G39:G53"), Me.UsedRange)

            r.EntireRow.Hidden = (UCase(r.Value) = "")

        Next r

Application.EnableEvents = True

    End If

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

        Application.EnableEvents = False:

'

'Code here to do stuff because T36 changed

'

Application.EnableEvents = True

    End If

FallThrough:

    Application.EnableEvents = True

End Sub

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote