• find method (2002 xp)

    Author
    Topic
    #456116

    Hi all,
    I am confused about the find method, when I am in the active sheet i have no problem finding my value, but when I am trying to set the sheet then find, I run into problems. Do I need to be on the active sheet to use the find method?

    Option Explicit
    Private Sub Lbcrew2_Click()
    Dim oscell As Range
    Dim irow As Integer
    Dim k As String
    k = “Somevalue”
    With Worksheets(2).Range(“A1:A500”)
    Set oscell = Cells.Find(k, , , , , xlNextTrue)
    With oscell
    irow = .Row
    End With
    End With

    End Sub

    Viewing 1 reply thread
    Author
    Replies
    • #1138253

      The unqualified Cells in the line
      Set oscell = Cells.Find(k, , , , , xlNextTrue)
      references the Active Sheet. Adding a dot
      Set oscell = . Cells.Find(k, , , , , xlNextTrue)

      will cause it to reference the sheet specified in the With statement

    • #1138254

      Make sure you use the other arguments of the find method, especially the start cell. Make sure it starts on the sheet you want it to.

    Viewing 1 reply thread
    Reply To: find method (2002 xp)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: