View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Vergel Adriano Vergel Adriano is offline
external usenet poster
 
Posts: 857
Default Change by Val like an "If" statement

David,

You could use the Select Case statement rather than If-Then-Else statements.
For example:

Select Case Range("X4").Value
Case "A":
'do something
Case "B":
'do something else
Case Else:
'value is neither A nor B
End Select

Lookup the VBA Help for the "Select case statement" to see an explanation
and example...



--
Hope that helps.

Vergel Adriano


"David P." wrote:

I would like to do a Change by Value change event like you would an IF
statement in a formula. Here is what I have but I need to add more ifs:

Private Sub Worksheet_Change(ByVal TargetCell As Range)
If (Range("X4") = "A") Then
more code here...

(I want to add 6 more of these types of things like:
If (Range("X4") = "B") Then
more code here...etc.

Is it possible to do this and if so how and how do I end it? Thank you.

David P.