+ Reply to Thread
Results 1 to 4 of 4

Problem with find method

Hybrid View

  1. #1
    Ralph Heidecke
    Guest

    Problem with find method

    I have the following code that looks for dates from an array that may
    already exist in a worksheet. When I test this code with a date in the array
    already put inthe worksheet the find results in nothing;

    what needs to be corrected?

    'load the dates in row B into the array

    Dim dtArray() As Date ' capture the selected dates
    Dim icol as Integer
    Dim ColCount as Integer
    Dim Colstep as Integer
    Dim i As Integer
    Dim c as Range

    ReDim dtArray(ColCount)
    For iCol = 1 To ColCount Step 1
    dtArray(iCol) = Cells(2, Colstep).Value
    Colstep = Colstep + 1
    Next iCol

    ' check if these dates were previously processed
    Worksheets("datecontrol").Activate
    With ActiveSheet.Usedrange ' the dates should be in Col A & it doesn't
    matter if I use Range("A:A") or put the date in A2 and say .Range("A2")
    For i = LBound(dtArray) To UBound(dtArray)
    Set c = .Find(what:=dtArray(i), Lookat:=xlWhole)
    If Not c Is Nothing Then
    ' c always ends up being "Nothing"
    MsgBox "This date may have been processed; " & c.Value & "
    terminating program"
    Application.ScreenUpdating = True
    Exit Sub
    End If

    Next i
    End With



  2. #2
    Jim Thomlinson
    Guest

    RE: Problem with find method

    There is nothing jumping out at me so lets start from the top...

    The date you are looking for exists in the used range?
    The date you are looking for is exactly the same as the date in the used
    range... right down to the minutes and seconds... One is not text while the
    other is an actual date?


    "Ralph Heidecke" wrote:

    > I have the following code that looks for dates from an array that may
    > already exist in a worksheet. When I test this code with a date in the array
    > already put inthe worksheet the find results in nothing;
    >
    > what needs to be corrected?
    >
    > 'load the dates in row B into the array
    >
    > Dim dtArray() As Date ' capture the selected dates
    > Dim icol as Integer
    > Dim ColCount as Integer
    > Dim Colstep as Integer
    > Dim i As Integer
    > Dim c as Range
    >
    > ReDim dtArray(ColCount)
    > For iCol = 1 To ColCount Step 1
    > dtArray(iCol) = Cells(2, Colstep).Value
    > Colstep = Colstep + 1
    > Next iCol
    >
    > ' check if these dates were previously processed
    > Worksheets("datecontrol").Activate
    > With ActiveSheet.Usedrange ' the dates should be in Col A & it doesn't
    > matter if I use Range("A:A") or put the date in A2 and say .Range("A2")
    > For i = LBound(dtArray) To UBound(dtArray)
    > Set c = .Find(what:=dtArray(i), Lookat:=xlWhole)
    > If Not c Is Nothing Then
    > ' c always ends up being "Nothing"
    > MsgBox "This date may have been processed; " & c.Value & "
    > terminating program"
    > Application.ScreenUpdating = True
    > Exit Sub
    > End If
    >
    > Next i
    > End With
    >
    >
    >


  3. #3
    gocush
    Guest

    RE: Problem with find method

    do you have any code left out above:

    ReDim dtArray(ColCount)
    For iCol = 1 To ColCount Step 1

    or is ColCount meant to be = 0

    "Ralph Heidecke" wrote:

    > I have the following code that looks for dates from an array that may
    > already exist in a worksheet. When I test this code with a date in the array
    > already put inthe worksheet the find results in nothing;
    >
    > what needs to be corrected?
    >
    > 'load the dates in row B into the array
    >
    > Dim dtArray() As Date ' capture the selected dates
    > Dim icol as Integer
    > Dim ColCount as Integer
    > Dim Colstep as Integer
    > Dim i As Integer
    > Dim c as Range
    >
    > ReDim dtArray(ColCount)
    > For iCol = 1 To ColCount Step 1
    > dtArray(iCol) = Cells(2, Colstep).Value
    > Colstep = Colstep + 1
    > Next iCol
    >
    > ' check if these dates were previously processed
    > Worksheets("datecontrol").Activate
    > With ActiveSheet.Usedrange ' the dates should be in Col A & it doesn't
    > matter if I use Range("A:A") or put the date in A2 and say .Range("A2")
    > For i = LBound(dtArray) To UBound(dtArray)
    > Set c = .Find(what:=dtArray(i), Lookat:=xlWhole)
    > If Not c Is Nothing Then
    > ' c always ends up being "Nothing"
    > MsgBox "This date may have been processed; " & c.Value & "
    > terminating program"
    > Application.ScreenUpdating = True
    > Exit Sub
    > End If
    >
    > Next i
    > End With
    >
    >
    >


  4. #4
    Ralph Heidecke
    Guest

    Re: Problem with find method

    > With ActiveSheet.Usedrange ' the dates should be in Col A & it doesn't
    > matter if I use Range("A:A") or put the date in A2 and say .Range("A2")
    > For i = LBound(dtArray) To UBound(dtArray)
    > Set c = .Find(what:=dtArray(i), Lookat:=xlWhole)


    using xlDate rather than xlWhole seems to have done the trick.

    "Ralph Heidecke" <[email protected]> wrote in message
    news:[email protected]...
    > I have the following code that looks for dates from an array that may
    > already exist in a worksheet. When I test this code with a date in the

    array
    > already put inthe worksheet the find results in nothing;
    >
    > what needs to be corrected?
    >
    > 'load the dates in row B into the array
    >
    > Dim dtArray() As Date ' capture the selected dates
    > Dim icol as Integer
    > Dim ColCount as Integer
    > Dim Colstep as Integer
    > Dim i As Integer
    > Dim c as Range
    >
    > ReDim dtArray(ColCount)
    > For iCol = 1 To ColCount Step 1
    > dtArray(iCol) = Cells(2, Colstep).Value
    > Colstep = Colstep + 1
    > Next iCol
    >
    > ' check if these dates were previously processed
    > Worksheets("datecontrol").Activate
    > With ActiveSheet.Usedrange ' the dates should be in Col A & it doesn't
    > matter if I use Range("A:A") or put the date in A2 and say .Range("A2")
    > For i = LBound(dtArray) To UBound(dtArray)
    > Set c = .Find(what:=dtArray(i), Lookat:=xlWhole)
    > If Not c Is Nothing Then
    > ' c always ends up being "Nothing"
    > MsgBox "This date may have been processed; " & c.Value & "
    > terminating program"
    > Application.ScreenUpdating = True
    > Exit Sub
    > End If
    >
    > Next i
    > End With
    >
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1