ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Excel macro activation. (https://www.excelbanter.com/excel-programming/272948-re-excel-macro-activation.html)

Dick Kusleika

Excel macro activation.
 
Kate

You can use the Change event, but I don't think it works on validation prior
to XL2000. You can check to see if the cell has validation using error
checking, then check the Value property of the Target (the cell that was
changed) for "B." It might look like this

Private Sub Worksheet_Change(ByVal Target As Range)

Dim x As Variant

On Error Resume Next
x = Target.Validation.ErrorMessage

If Err.Number = 0 Then
On Error GoTo 0
If UCase(Target.Value) = "B" Then
MsgBox "Do stuff"
End If
End If

End Sub

x is just a throw-away variable that's used to generate an error if there is
no validation in that cell. It will prevent the macro from running if
someone types a 'B' in a cell without validation as opposed to choosing it
from a validation list.

--
Dick Kusleika
MVP - Excel
www.dicks-clicks.com
Post all replies to the newsgroup.

"Kate Smith" wrote in message
om...
Here is my problem.

I have a dropdown list in multiple cells that I've created using data
validation feature. For example, my list contains 3 items: A,B,and C.
I also have a macro that I want to run but ONLY if the user chooses
item B from the list. If he/she chooses either items A or C, I don't
want the macro to run. Since my list contains words, I don't know if
there's a way of triggering a macro with a keyword as opposed to
attaching it to some sort of a button.

There are many rows that use this dropdown list and I was trying to
see if there's a way of doing that without having to create buttons.

I greatly appreciate any suggestions. Thanks.

Kate.





All times are GMT +1. The time now is 02:48 PM.

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