Consulting

Results 1 to 4 of 4

Thread: Solved: .Find not working between Workbooks

  1. #1
    VBAX Expert CatDaddy's Avatar
    Joined
    Jun 2011
    Posts
    581
    Location

    Solved: .Find not working between Workbooks

    error in highlighted section...RT error 91 object variable or with block not set...the same formula works between two sheets of the same workbook...but not two separate workbooks?!?!?!


    [VBA]For i = 3 To lRow
    Set findStr = Workbooks(wb).Sheets(1).Range("C" & i)
    Workbooks(wbA).Sheets(1).Activate

    Range("B1:B2000").Find _
    (What:=findStr, _
    LookIn:=xlValues, _
    LookAT:=xlPart, _
    SearchOrder:=xlByRows).Activate

    foundCell = ActiveCell.Offset(0, -1).Value
    Workbooks(wb).Worksheets(1).Cells(i, 9).Value = foundCell
    Next i[/VBA]
    ------------------------------------------------
    Happy Coding my friends

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    This code wouldn't be in a sheet's code module would it (a sheet which isn't Workbooks(wbA).Sheets(1))?

    Untested, try:[vba]With Workbooks(wb).Sheets(1)
    For i = 3 To lRow
    Set findStr = .Range("C" & i)
    Set c = Workbooks(wbA).Sheets(1).Range("B1:B2000").Find _
    (What:=findStr, _
    LookIn:=xlValues, _
    LookAT:=xlPart, _
    SearchOrder:=xlByRows)
    If Not c Is Nothing Then .Cells(i, 9).Value = c.Offset(0, -1).Value
    Next i
    End With
    [/vba]
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    VBAX Expert CatDaddy's Avatar
    Joined
    Jun 2011
    Posts
    581
    Location
    i used Match instead...i didnt need the value just the location...

    [VBA]For i = 3 To lRow
    Set findStr = Workbooks(wb).Worksheets(1).Range("C" & i)

    Workbooks(wbA).Worksheets(1).Activate

    On Error Resume Next
    sRow = Application.Match(findStr, Range("B:B"), 0)
    If Err.Number <> 0 Then
    'no match found
    Err.Clear
    Else
    foundCell = Cells(sRow, 1).Value
    Workbooks(wb).Worksheets(1).Activate
    Cells(i, 9).Value = foundCell
    End If
    Next i[/VBA]
    ------------------------------------------------
    Happy Coding my friends

  4. #4
    VBAX Expert CatDaddy's Avatar
    Joined
    Jun 2011
    Posts
    581
    Location
    turns out the problem was the woman i work with gave me the wrong source sheet...the error was just because the values didnt exist in the second workbook (only 60000 lines )
    ------------------------------------------------
    Happy Coding my friends

Posting Permissions

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