View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_5_] Bob Phillips[_5_] is offline
external usenet poster
 
Posts: 620
Default If... Then Loop problems in Worksheet Event

What exactly is not working, what do you get?

--

HTH

Bob Phillips

"TB" wrote in message
...
I can't seem to get the following code to work properly:

Option Explicit
Private Sub Worksheet_Change(ByVal target as Excel.Range))
Dim strDay as String
On Error Resume Next
Application.EnableEvents = False
If Range("E10").Cells.Value + Range("B10").Cells.Value = 16 Then
Range("H10").Cells.Value = Range("H10").Cells.Value + 4
Range("H17").Cells.Value = Range("H17").Cells.Value + 4
strDay = " (" & ActiveCell.Offset(-1,-4).Value & ") "
Sheets(1).Range("B26").Value = Sheets(1).Range("B26").Value_
& strDay & " Working floating holiday @ time and a half."
End If
If Range("E11").Cells.Value + Range("B11").Cells.Value = 16 Then
Range("H10").Cells.Value = Range("H10").Cells.Value + 4
Range("H17").Cells.Value = Range("H17").Cells.Value + 4
strDay = " (" & ActiveCell.Offset(-1,-4).Value & ") "
Sheets(1).Range("B26").Value = Sheets(1).Range("B26").Value_
& strDay & " Working floating holiday @ time and a half."
End If
Application.EnableEvents = True
End Sub

There are a total of seven If... Then statements for E10 through E16. If

the
conditions in any of these cells are met, the following line of text is
inserted into cell B26 (Example for E10):

(Sunday) Working floating holiday @ time and a half.

If data is entered into a second cell, (i.e. cell E11), the following
double entry is generated:

(Sunday) Working floating holiday @ time and a half.
(Monday) Working floating holiday @ time and a half.
(Monday) Working floating holiday @ time and a half. (extra line

generated)

A third entry generates a triple entry, etc. Can anyone help me with this?

I'd also appreciate a routine for deleting the appropriate line of text if
the user goes back and deletes the data in one of the cells.