Macro save data to then load new data?

Problem

The list box on sheet “Step 3 - Define Causal Factors” is where users select the Event to work on. The system is designed to handle a maximum of five events. In the upper right had corner of sheet “Step 3 - Define Causal Factors” there is a series of LOAD and SAVE buttons.

The macros assigned to the buttons either load all the data for the selected event or save all the data for the selected event.
The problem is when a user the list box to select a different event. The macro does not save the data to the existing event before changing to the new event. There are 5 load macros and 5 save events.

How can I solve this problem?
Root-Cause-Analysis-Ver-14.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.

FamousMortimerCommented:
Hi,

See attached...  I changed the listbox form control to an activex listbox control which has events that are can be handled.  In this example i added the code below to sheet 'Step 3 - Define Causal Factors'.  Basically, it triggers when a mouse button is pressed down (so before the mouse click is complete) and uses a case statement based on the index of the item clicked to determine which save to perform.

'this will trigger before the selection changes
Private Sub ListBox1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    'make sure it is the left mouse button that is clicked
    If Button = vbKeyLButton Then
        Select Case ListBox1.ListIndex
            'the index of the list items are zero-based so the first item is index 0
            Case 0
                Call Save1
            Case 1
                Call Save2
            Case 2
                Call Save3
            Case 3
                Call Save4
            Case 4
                Call Save5
        End Select
    End If
End Sub

Open in new window

Root-Cause-Analysis-Ver-14.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.