View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Dave D-C[_3_] Dave D-C[_3_] is offline
external usenet poster
 
Posts: 176
Default Simple VBA question

You need to have your code as an event handler.
Go to the code for a sheet (right click a sheet tab).
Then
Private Sub Worksheet_Change( _
ByVal Target As Excel.Range)
Dim x As Integer
MsgBox target.address ' didactic
If Intersect(Target, Range("a1")) Is Nothing Then Exit Sub
x = Range("A1").Value
If x = 1 Then
MsgBox "invalid number in cell A1"
End If
End Sub


Aaron wrote:
Public Sub firsttry()
Dim x As Integer
x = Range("A1").Value
If x = 1 Then
MsgBox "invalid number in cell A1"
End If
End Sub

I have to run the macro for the msgbox to appear. How can it pop up as soon
as the number 1 is entered in cell A1?