Macros not triggered after drop down list selection

abstracto

New Member
Joined
Jan 11, 2023
Messages
6
Hello everyone

Glad to join the forum!

I have an issue with macros in an excel file I'm working on. I attached worsheet screen shots for reference.
Sheet 'calculation has all the formulas'. Sheet ' drop down list info' has info for drop down lists (2 used in the main sheet).

There's a drop down list in the cell D6 that has 3 options: SEA, AIR and SEA+AIR.

I created 3 macros that should be triggered based on option selection from above mentioned drop down list.

SEA and AIR macro basically just hides selected rows. SEA+AIR macro unhides all. Each macro also goes back to cell D6 at the end.

However it doesn't seem to work at all. I have checked several forums but couldn't find a solution to my problem.

If I run macros manually everything works well.

Please advise what kind of mistake I did. I must say that I have completely no idea about VB and all the cose used in macros comes from recording macros step by step and then adjusting it a bit based on what I found online.

Thanks in advance for your kind help!

Macros code below:


VBA Code:
Sub SEA()
'
' SEA Macro
'

'
    Rows("14:20").Select
    Selection.EntireRow.Hidden = True
    Rows("7:13").Select
    Selection.EntireRow.Hidden = False
    Range("D6").Select
    
End Sub

Sub AIR()
'
' AIR Macro
'

'
    Rows("7:13").Select
    Selection.EntireRow.Hidden = True
    Rows("14:20").Select
    Selection.EntireRow.Hidden = False
    Range("D6").Select

End Sub
 
Sub BOTH()
'
' BOTH Macro
'

'
    Sheet.Select
    Selection.Sheet.Hidden = False
    Range("D6").Select

End Sub
 

Attachments

  • calculation sheet.png
    calculation sheet.png
    139.7 KB · Views: 27
  • drop down list info sheet.png
    drop down list info sheet.png
    107.6 KB · Views: 29

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Welcome to the MrExcel Message Board! :)

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at:

There is no need to repeat the link(s) provided above but if you have posted the question at other places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0
Hi RoryA

Thanks for your message!

Well noted on cross-posting. I'll follow your advice in the future definitely!
Just trying to reach wider audience for a higher chance of help if possible.
 
Upvote 0
You need some code to trigger when you make a change in cell D6. Paste this event macro to your sheet's module. Then consider that you have an issue in your BOTH macro but I will leave this up to you as 'homework'.
VBA Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Target, Range("D6")) Is Nothing Then Exit Sub
    Select Case Target
        Case Is = "SEA"
            Call SEA
        Case Is = "AIR"
            Call AIR
        Case Is = "SEA+AIR"
            Call BOTH
    End Select
End Sub
 
Upvote 0
Thanks for the positive feedback(y), glad having been of some help. Since I have yet to do my daily BoyScout good deed, here:
VBA Code:
Sub BOTH()
    '
    ' BOTH Macro
    '
    Cells.Select
    Selection.EntireRow.Hidden = False
    Range("D6").Select
End Sub
 
Upvote 0
So I pasted above code and still nothing happens :(

(I haven't addressed Both yet.)

It looks like below now:

VBA Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Target, Range("D6")) Is Nothing Then Exit Sub
    Select Case Target
        Case Is = "SEA"
            Call SEA
        Case Is = "AIR"
            Call AIR
        Case Is = "SEA+AIR"
            Call BOTH
    End Select
End Sub
Sub SEA()
' SEA Macro
    Rows("14:20").Select
    Selection.EntireRow.Hidden = True
    Rows("7:13").Select
    Selection.EntireRow.Hidden = False
    Range("D6").Select
    
End Sub
Sub AIR()
' AIR Macro
    Rows("7:13").Select
    Selection.EntireRow.Hidden = True
    Rows("14:20").Select
    Selection.EntireRow.Hidden = False
    Range("D6").Select

End Sub
Sub BOTH()
' BOTH Macro
    Sheet.Select
    Selection.Sheet.Hidden = False
    Range("D6").Select

End Sub
 
Upvote 0
Sorry, in post #4 I said that (at least) the event Worksheet_Change macro must go in the sheet's module (sheet Calculation).
 
Upvote 0
Thanks!

It looks like this now (attached)

Module 1

VBA Code:
Sub SEA()
' SEA Macro
    Rows("14:20").Select
    Selection.EntireRow.Hidden = True
    Rows("7:13").Select
    Selection.EntireRow.Hidden = False
    Range("D6").Select
    
End Sub
Sub AIR()
' AIR Macro
    Rows("7:13").Select
    Selection.EntireRow.Hidden = True
    Rows("14:20").Select
    Selection.EntireRow.Hidden = False
    Range("D6").Select

End Sub
Sub BOTH()
    '
    ' BOTH Macro
    '
    Cells.Select
    Selection.EntireRow.Hidden = False
    Range("D6").Select
End Sub


Module 2

VBA Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Target, Range("D6")) Is Nothing Then Exit Sub
    Select Case Target
        Case Is = "SEA"
            Call SEA
        Case Is = "AIR"
            Call AIR
        Case Is = "SEA+AIR"
            Call BOTH
    End Select
End Sub


Or I mixed something up? :(
 

Attachments

  • modules.png
    modules.png
    83.3 KB · Views: 16
Upvote 0
No, not in Module2, move it to Sheet1 (calculation). That's where you have your cell D6 with it's dropdown list that has to trigger an event macro. when it changes.
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

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