Why is my macro not running?

I have code on sheet "Step 3 - Define Causal Factors" that is attached to 'List Box 21" and it should run one of the 5 macros.

It is not working.

Please advice.

+++++++++++++++++++++++++++++++++++++++++++++++++

  Private Sub List_Box_21_Change()


      If List_Box_21_Change.ListIndex > -1 Then
          Select Case List_Box_21.Value
          Case "One": Run "Load_1"
          Case "Two": Run "Load_2"
         Case "Three": Run "Load_3"
          Case "Four": Run "Load_4"
          Case "Five": Run "Load_5"
End Select
    End If
    End Sub
Root-Cause-Analysis-Ver-17.xlsm
cssc1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NorieVBA ExpertCommented:
It's a form listbox, so the code for it should go in a standard module and you should assign it to the control.

Add a new module (Insert>Module) and paste this code in it.
Sub List_Box_21_Change()

    If Sheets("Step 3 - Define Causal Factors").ListBoxes("List Box 21").ListIndex > -1 Then
        Select Case Sheets("Step 3 - Define Causal Factors").ListBoxes("List Box 21").Value
            Case "One": Run "Load_1"
            Case "Two": Run "Load_2"
            Case "Three": Run "Load_3"
            Case "Four": Run "Load_4"
            Case "Five": Run "Load_5"
        End Select
    End If
    
End Sub

Open in new window

Then right click List Box 21, select Assign Macro, select List_Box_21 from the dialog and press OK.

The code should then run but it won't do anything as the values in the code don't match up with those in the listbox.
0
Ejgil HedegaardCommented:
The element is not an active-x listbox, but a formular control element.
When I right click on it, the name in the name box (upper left corner just above the sheet) is "Liste 21", but probably Excel translates to local name, so check to insert the correct list name in the macro.
The macro can not be Private, to be able to connect the element to the macro.
Then this macro works

Sub List_Box_21_Change()
    If [Liste 21].ListIndex > -1 Then
        Select Case [Liste 21].Value
            Case 1: Run "Load_1"
            Case 2: Run "Load_2"
            Case 3: Run "Load_3"
            Case 4: Run "Load_4"
            Case 5: Run "Load_5"
        End Select
    End If
End Sub

Open in new window

0
NorieVBA ExpertCommented:
Here's the workbook with the code updated.
Root-Cause-Analysis-Ver-17.xlsm
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.