Running a macro based on a specific ListBox selection

jmpatrick

Active Member
Joined
Aug 17, 2016
Messages
477
Office Version
  1. 365
Platform
  1. Windows
Happy Friday!

Today I'm trying to run a macro based on a specific ListBox selection on a Sheet and in a named range.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
 
    If Not Intersect(Target, Range("CalendarGarageHandlingColumn")) Is Nothing Then
 
    Select Case Range("CalendarGarageHandlingColumn")
 
        Case "<ADD NEW>": OpenAddNewGarageHandling

    End Select
    End If
 
End Sub

<ADD NEW> is one of the choices and I need to run OpenAddNewGarageHandling only when it is selected. The macro is in a Module.

I'm getting an error: Run-time error '13': Type mismatch

It's bumming me out.
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
After messing with this it's starting to look like the fact that the drop-down is on a sheet rather than a UserForm is what's tripping me up.
 
Upvote 0
I have looked at you script but not sure what you trying to do.
You have your script as a sheet change event script but then say your script is in a module.
OK: What does the script in the module look like? Show me the script.
And what is:
If Not Intersect(Target, Range("CalendarGarageHandlingColumn")) Is Nothing
Is this a Column on your worksheet name Calendar Garage?
 
Upvote 0
Some progress. The problem appears to be the named range. When I change to a single cell rather than a range it works for that cell...
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
 
    If Not Intersect(Target, Range("H868")) Is Nothing Then
 
    Select Case Range("H868")
 
        Case "<ADD NEW>": OpenAddNewGarageHandling

    End Select
    End If
 
End Sub

Now I need to get it working with a range.
 
Upvote 0
I have looked at you script but not sure what you trying to do.
You have your script as a sheet change event script but then say your script is in a module.
OK: What does the script in the module look like? Show me the script.
And what is:
If Not Intersect(Target, Range("CalendarGarageHandlingColumn")) Is Nothing
Is this a Column on your worksheet name Calendar Garage?

CalendarGarageHandlingColumn is the named range. The macro simply opens a UserForm to a specific tab and field...

VBA Code:
Sub OpenAddNewGarageHandling()
Settings.Show
Settings.MultiPage1.Value = 7
Settings.NewGarageHandlingName.SetFocus
End Sub
 
Upvote 0
So talk to me a little.
So Settings is the Name of the userform Correct?
And what does this suppose to do?
Settings.NewGarageHandlingName.SetFocus

Set focus to what?
 
Upvote 0
So talk to me a little.
So Settings is the Name of the userform Correct?
And what does this suppose to do?
Settings.NewGarageHandlingName.SetFocus

Set focus to what?

Correct, Settings is the Userform.

NewGarageHandlingName is a field on the UserForm.

The Macro works fine. This code works fine with a specific cell targeted:

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
 
    If Not Intersect(Target, Range("H868")) Is Nothing Then
 
    Select Case Range("H868")
 
        Case "<ADD NEW>": OpenAddNewGarageHandling

    End Select
    End If
 
End Sub

I'm now trying to get it to work on a named range (CalendarGarageHandlingColumn).
 
Upvote 0
Well here is a script I wrote that gives you a example:
Range is named "ans"
If you enter "Yes" in Range named "ans" you get a message box to pop up.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
 'Modified  11/19/2021  12:24:55 PM  EST
    If Not Intersect(Target, Range("Ans")) Is Nothing Then
        Select Case Range("Ans")
            Case "Yes": MsgBox "Hello"
        End Select
    End If
 
End Sub
 
Upvote 0
Well here is a script I wrote that gives you a example:
Range is named "ans"
If you enter "Yes" in Range named "ans" you get a message box to pop up.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
 'Modified  11/19/2021  12:24:55 PM  EST
    If Not Intersect(Target, Range("Ans")) Is Nothing Then
        Select Case Range("Ans")
            Case "Yes": MsgBox "Hello"
        End Select
    End If
 
End Sub

That's exactly the code that I put in my original post, other than I used my existing named range.
 
Upvote 0
And I do not understand this:
"<ADD NEW>"

Your actually entering: <ADD NEW>
Or is it ADD NEW
 
Upvote 0

Forum statistics

Threads
1,215,580
Messages
6,125,654
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