Running a Macro based on Forms Combo Box

mtampa

Board Regular
Joined
Oct 15, 2007
Messages
61
Hi Guys,

I have a forms combo box that outputs to cell K3. When item 3 is selected and the value in cell K3 = 3, I want my macro called EMPVILL to run. However, it only fires when I type a 3 in the box and hit enter. As of now, when I change the value of the combo box to 1, 2, 3 or 4, nothing happens, it just sits there.

Here is the code I'm using:

rivate Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Address = "$K$3" Then
Select Case Target.Value
Case Is = 3: Call EMPVILL
Case Else: 'Do Nothing
End Select
End If
End Sub

Can someone point me in the right direction to make it fire when cell K3 changes to the value of 3?

Thanks,

Mike
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Hi All - I'm still struggling with this topic...does anyone have any solutions to my issue? If you need a copy of my worksheet, I'd be more then happy to send it to you.

Thanks,

Mike
 
Upvote 0
Instead of a Worksheet_Change procedure, assign a macro to the Form combobox that tests the value of K3. The assigned macro is triggered each time you change the combobox.

Assign this to your combobox. Right-click on the combobox and select Assign Macro.
Code:
Sub Test_K3()
    If Range("K3").Value = 3 Then Call EMPVILL
End Sub
 
Upvote 0
Wow, making progress! It did it but now it runs the macro no matter what I select....option 1, 2 or 3 all trigger it.
 
Upvote 0
The macro Test_K3 is triggered every time you change the combobox, but it only should call EMPVILL when K3 equals 3.

EDIT: Just saw your never mind message.
 
Upvote 0
Actually I jumped the gun two times.

I thought I had an error but do not.

Yes, you are correct, the macro should only run when the combo box selects choice three but it is indeed running every time a selection is made. My idea of what was wrong proved to be a non-issue.
 
Upvote 0
I think we're a bit off on our replies AlphaFrog....I haven't quite resolved it. If you could help me figure out why I runs every time any selection is made, I'd appreciate it.

Thanks,

Mike
 
Upvote 0

Forum statistics

Threads
1,224,545
Messages
6,179,432
Members
452,915
Latest member
hannnahheileen

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