Greetings Peter,
First, a correction to my suggestion at #4, as indeed, the new data being added to the cells in Col's C:G must enter before the time hack gets put in whatever row of Col A. Sorry about that. Presuming that you tried this code, you must have the time-hack being entered first. Was it difficult to change the order of things so that the values are entered first and then the time-hack?
Reference your last code, I believe you have more than "one small problem" with it. Let's take a step back and look:
[vba]If WorksheetFunction.CountA(Cells) > 0 Then[/vba] Sorry, but given that the unqualified Cells returns all the cells on the sheet(!), this literally translates to: "If ANY cell (even just one) on the entire sheet has anything in it, then go ahead and... (find the last row)". Now of course this test will always be passed, but if it ever did return a FALSE, then 'LastRow' would not get a value assigned and a fatal error would occur at the line that Sets 'checkrange'.
Now before looking at your .Find, let's look at the formula you have plastered in all the cells in Columns A:G. Does the version of Excel you are using (presumably Dutch) use semi-colons as seperators? If so, then I'm pretty sure that this would be the equivalent of:
IF((ISBLANK(Sheet1!D9)),NA(),Sheet1!D9*1)
Or
IF(ISBLANK(Sheet1!D9),NA(),Sheet1!D9*1)
Or
IF(ISBLANK(Sheet1!D9),NA(),Sheet1!D9)
Why would you would multiply D9 by 1.00? At least as far as I can see, this leaves three possibilities: (1) A number in D9 results in the same number in all the cells, (2) nothing (blank) in D9 results in the Not Available error in all the cells, or (3) a text entry in D9 results in the Value error in all the cells. Now since you stated that all the cells in Columns A:G contain NA(), I presume you leave Sheet1 (Blad1) cell D9 blank. If the NA() is really necessary, why not just enter it?
Now with all the NA()s... In regards to your question as to .Find, I do not know a way for it to directly do this. You could of course use FindNext in a do...loop until it runs into a number, but this would seem both slow (Your .Find starts at Cell IV65536) and unnecessary. Hows about we try skipping the .Find part alltogether:
Option Explicit
Private Declare Function sndPlaySound32 Lib "winmm.dll" _
Alias "sndPlaySoundA" (ByVal lpszSoundName _
As String, ByVal uFlags As Long) As Long
'// Change to suit. //
Const sPath As String = "C:\Program Files\NetMeeting\"
Const sWav As String = "TestSnd.wav" '"ltdd_024.wav"
'
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rCell As Range
Dim bolSurpassed As Boolean
'// See if the cell(s) that got changed are in the range we care about, and that //
'// we're not just clearing a bunch of contents... //
If Not Application.Intersect(Range("C:G"), Target) Is Nothing _
And Not Selection.Cells.Count > 1 Then
'// This should work regardless of whether the data is being entered a cell at //
'// time, or as an array (all at once). //
For Each rCell In Target
If rCell.Value > Cells(1, 19) Then
'// If we find a value greater than that which is in S1, flag as true //
'// and exit the loop. //
bolSurpassed = True
Exit For
End If
Next
'// If we flagged true, play the sound. //
If bolSurpassed Then Call sndPlaySound32(sPath & sWav, 1)
End If
End Sub
To test, you could paste the below in a standard module. From your description thus far, I believe these cover the possibilities; those being: Data is entered a cell at a time before the time hack is entered, or time-hack first then data, or data is entered (before or after) all at once (array).
Sub Test_1()
Dim r As Range
Set r = Cells(Rows.Count, 1).End(xlUp).Offset(1)
r = Now()
Set r = Range(Cells(r.Row, 3), Cells(r.Row, 7))
r = Array(12, 13, 14, 9, 7)
End Sub
Sub Test_2()
Dim r As Range, r2 As Range
Set r = Cells(Rows.Count, 1).End(xlUp).Offset(1)
Set r2 = Range(Cells(r.Row, 3), Cells(r.Row, 7))
r2 = Array(12, 13, 14, 9, 7)
r = Now()
End Sub
Sub Test_3()
Dim r As Range
Set r = Cells(Rows.Count, 1).End(xlUp).Offset(1)
r = Now()
r.Offset(, 2).Value = 22
End Sub
Sub Test_4()
Dim r As Range
Set r = Cells(Rows.Count, 1).End(xlUp).Offset(1)
r.Offset(, 3).Value = 22
r = Now()
End Sub
Hope this helps,
Mark