Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default If... Then Loop problems in Worksheet Event

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.


  #2   Report Post  
Posted to microsoft.public.excel.programming
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.




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default If... Then Loop problems in Worksheet Event

Bob, I put an example of the output after the code. It outputs the text
correctly if only one cell in column E has data in it (data is either "8" or
and empty cell). Entering a second "8" causes the routine to output two
lines of text, a third causes three lines, etc. For example, assuming that
columns B10 through B14 all have "8" entered in them, and I insert an "8" in
E10, E11, and E12, I will get the following output:

(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 unwanted line)
(Tuesday) Working floating holiday @ time and a half
(Tuesday) Working floating holiday @ time and a half (extra unwanted line)
(Tuesday) Working floating holiday @ time and a half (extra unwanted line)

Looking at the code, I know why it's doing it. I just don't know of a way to
stop it from reading the previous entries in that column more than once. Any
help is welcome.

Regards
Tom

"Bob Phillips" wrote in message
...
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.






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with worksheet event NZuser Excel Worksheet Functions 6 April 20th 09 11:01 AM
MenuBar & Event problems Graham F Excel Discussion (Misc queries) 1 May 7th 06 10:26 AM
Excel Macro loop problems mibsaweiss Excel Discussion (Misc queries) 0 March 16th 06 04:45 PM
Worksheet Change Event TonyM Excel Discussion (Misc queries) 8 March 11th 05 12:52 PM
macro to apply worksheet event to active worksheet Paul Simon[_2_] Excel Programming 3 August 7th 03 02:50 AM


All times are GMT +1. The time now is 10:38 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"