+ Reply to Thread
Results 1 to 7 of 7

Find Query

Hybrid View

  1. #1
    Registered User
    Join Date
    07-30-2010
    Location
    Warrington, England
    MS-Off Ver
    Excel 2010
    Posts
    71

    Question Find Query

    Hi,

    I have a value in A1 on Sheet1 of a workbook and, for each instance of the same value in column D on Sheet2, I need to copy the values in the next 2 adjacent cells and paste them to Column K-L on Sheet3. I'm guessing that FIND is a better way than using vlookup but then I get totally lost. Can anyone help please?

    Many thanks

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Find Query

    Yes, it looks like. Could you please attach a sample book with a desired result?

  3. #3
    Registered User
    Join Date
    07-30-2010
    Location
    Warrington, England
    MS-Off Ver
    Excel 2010
    Posts
    71

    Re: Find Query

    Many thanks in anticipation, here's a workbook which i've simplified for this purpose

    M

    Book1.xls

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Find Query

    Mike,
    Try this one and see how it goes.

    Sub find_copy()
    Dim c2 As Range, c As Range
    With Sheets("Sheet2")
     For Each c2 In .Range("B2:B" & .Cells(Rows.Count, 3).End(xlUp).Row).SpecialCells(12)
       Set c = Sheets("Sheet1").Columns(1).Find(c2, , xlValues, xlWhole)
        If Not c Is Nothing Then
        c2.Offset(, 3).Resize(, 2).Copy Sheets("sheet3").Cells(Rows.Count, 11).End(xlUp).Offset(1).Resize(, 2)
        End If
       Next c2
     End With
    End Sub

  5. #5
    Registered User
    Join Date
    07-30-2010
    Location
    Warrington, England
    MS-Off Ver
    Excel 2010
    Posts
    71

    Re: Find Query

    Many thanks!! This almost works perfectly. It copies the column headers each time it runs for some reason though

  6. #6
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Find Query

    Mike! Sorry Mate!
    It was actually a wrong code. The code was looking at Columns "B", instead of D.
    I think this is correct.

    Sub find_copy()
    Dim c2 As Range, c As Range
    With Sheets("Sheet2")
    LR = .UsedRange.Rows.Count
    On Error Resume Next
     For Each c2 In .Range("D2:D" & LR)
       Set c = Sheets("Sheet1").Columns(1).Find(c2, , xlValues, xlWhole)
        If Not c Is Nothing Then
        c2.Offset(, 2).Resize(, 2).Copy Sheets("sheet3").Cells(Rows.Count, 11).End(xlUp).Offset(1).Resize(, 2)
        End If
       Next c2
     End With
    End Sub

  7. #7
    Registered User
    Join Date
    07-30-2010
    Location
    Warrington, England
    MS-Off Ver
    Excel 2010
    Posts
    71

    Re: Find Query

    Hi, apologies for the delay getting back to you. Your re-posted code works perfectly! Many thanks again for your help

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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