ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Event Macro help (https://www.excelbanter.com/excel-programming/408322-event-macro-help.html)

Ted Metro

Event Macro help
 
I have this change macro and in o1 I have the cell link for a combo-box.
When a value is selected in the combo-box the number changes in o1, but it
does not trigger my event macro because I'm not changing the value it's
simply updating from the combo-box.

How can I write my event macro so that it will trigger from a user changing
a value in my combo-box?

Have a good day!

Ted


Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count 1 Then Exit Sub
On Error GoTo ErrHandler
If Not Intersect(Target, Range( _
"o1:o3, o1:o5")) Is Nothing Then
Application.EnableEvents = False
Range("h6:h10").Select
With Selection.Interior
.ColorIndex = 44
.Pattern = xlSolid
End With
End If
ErrHandler:
Application.EnableEvents = True
End Sub

JLGWhiz

Event Macro help
 
Right click the combo box View Code, and if it does not automatically
appear then click the declarations window and look for this:

Private Sub ComboBox1_Change()

End Sub

Put you code inside this and it will execute with each selection change.


"Ted Metro" wrote:

I have this change macro and in o1 I have the cell link for a combo-box.
When a value is selected in the combo-box the number changes in o1, but it
does not trigger my event macro because I'm not changing the value it's
simply updating from the combo-box.

How can I write my event macro so that it will trigger from a user changing
a value in my combo-box?

Have a good day!

Ted


Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count 1 Then Exit Sub
On Error GoTo ErrHandler
If Not Intersect(Target, Range( _
"o1:o3, o1:o5")) Is Nothing Then
Application.EnableEvents = False
Range("h6:h10").Select
With Selection.Interior
.ColorIndex = 44
.Pattern = xlSolid
End With
End If
ErrHandler:
Application.EnableEvents = True
End Sub


Ted Metro

Event Macro help
 
Wow, that was too easy. Thanks!!

"JLGWhiz" wrote:

Right click the combo box View Code, and if it does not automatically
appear then click the declarations window and look for this:

Private Sub ComboBox1_Change()

End Sub

Put you code inside this and it will execute with each selection change.


"Ted Metro" wrote:

I have this change macro and in o1 I have the cell link for a combo-box.
When a value is selected in the combo-box the number changes in o1, but it
does not trigger my event macro because I'm not changing the value it's
simply updating from the combo-box.

How can I write my event macro so that it will trigger from a user changing
a value in my combo-box?

Have a good day!

Ted


Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count 1 Then Exit Sub
On Error GoTo ErrHandler
If Not Intersect(Target, Range( _
"o1:o3, o1:o5")) Is Nothing Then
Application.EnableEvents = False
Range("h6:h10").Select
With Selection.Interior
.ColorIndex = 44
.Pattern = xlSolid
End With
End If
ErrHandler:
Application.EnableEvents = True
End Sub



All times are GMT +1. The time now is 08:11 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com