View Single Post
  #6   Report Post  
Jim Cone
 
Posts: n/a
Default

Casey,

If you absolutely sure that numeric values only will be used in
the worksheet than a data type of Double is what I would use.
Numeric values are returned as Doubles from a worksheet range.
To use another data type forces Excel to convert the value.
It you are not positive about what will be entered into the cells then use a variant.

Yes it is necessary to use something similar to the error handling
I wrote. If the code ever threw an error, then you would have events
disabled in the entire Excel application.

Its usually best to have error handling included in all code.
Even if you want the code to continue on despite any errors,
you can be alerted to the fact that something went wrong with...

On Error Goto Err_Handler
'Code here
Exit sub
Err_Handler:
Beep
Resume Next
End Sub
'------------
Regards,
Jim Cone


"Casey" wrote in message

Jim,
Thank you so much for the help. I got what I needed with the Enable
Events. I tried running your code but it cleared the entire first 5
columns whenever I put a "1" in any row in the 6th column, not what I
was looking for. Below is the Code I pasted together with your input.
Two questions if you have time. One, is it necessary to change the N
varible data type to variant? Two is the error handling procedure
necessary, do I need to incorporate it into my revised code? Thanks
again Jim for the code and the cascading event lesson, I really
appreciate your time.

Here's my revised code which works great.

Private Sub Worksheet_Change(ByVal Target As Range)
Dim i As Integer
Dim N As Integer
Dim wks1 As Worksheet

Set wks1 = Worksheets("SET UP SHT(1)")
Application.EnableEvents = False

If Not Intersect(Target, Range("E23:J27")) Is Nothing Then

For i = 23 To 27
N = wks1.Cells(i, 10).Value
If N = 1 Then
Cells(i, 5) = 0
Cells(i, 6) = 0
Cells(i, 7) = 0
Cells(i, 8) = 0
Cells(i, 9) = 0
End If
Next i
End If
Application.EnableEvents = True
End Sub
--
Casey