Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 102
  • Last Modified:

Excel forumal to copy data from one tab to another when one column matches

I have an excel file with two tabs (Report & ABC)

Report is my main table and I would like to copy some fields into it from Tab ABC when there is a match on two columns...

Logic...

Formula
When value in column B (Report) is found anywhere in column A of (ABC)
Copy (ABC) Column C to (Report) Column U
0
Matt Pinkston
Asked:
Matt Pinkston
  • 3
  • 2
1 Solution
 
Matt PinkstonAuthor Commented:
and if there is no find or the value in (ABC) column C is blank return a value of "No Rating"
0
 
Martin LissRetired ProgrammerCommented:
Here's a macro you can use. If you need help implementing the macro please let me know.

Sub FindAndCopy()

Dim rngFound As Range
Dim lngLastRow As Long
Dim lngRow As Long
lngLastRow = Range("B1048576").End(xlUp).Row

    Sheets("Report").Activate
    For lngRow = 1 To lngLastRow
        If Sheets("Report").Cells(lngRow, 2) <> "" Then
            With Sheets("ABC").Range("A:A")
                Set rngFound = .Cells.Find(What:=Sheets("Report").Cells(lngRow, 2), LookIn:=xlFormulas, LookAt _
                    :=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
                    False, SearchFormat:=False)
                If Not rngFound Is Nothing Then
                    If Sheets("ABC").Cells(rngFound.Row, 3) <> "" Then
                        Sheets("Report").Cells(lngRow, 21) = Sheets("ABC").Cells(rngFound.Row, 3)
                    Else
                        Sheets("Report").Cells(lngRow, 21) = "No Rating"
                    End If
                Else
                    Sheets("Report").Cells(lngRow, 21) = "No Rating"
                End If
            End With
        End If
    Next
End Sub

Open in new window

0
 
Rob HensonIT & Database AssistantCommented:
If I have understood the requirement, I think you can use a VLOOKUP formula for this, in column U of Report:

=IF(VLOOKUP(Report!B1,ABC!A:C,3,FALSE)=0,"No Rating",VLOOKUP(Report!B1,ABC!A:C,3,FALSE))

Copied down as far as required.

Thanks
Rob H
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Rob HensonIT & Database AssistantCommented:
Amendment to allow for No Find:

=IF(OR(ISERROR(VLOOKUP(Report!B1,ABC!A:C,3,FALSE)),VLOOKUP(Report!B1,ABC!A:C,3,FALSE)=0),"No Rating",VLOOKUP(Report!B1,ABC!A:C,3,FALSE))

Thanks
Rob H
0
 
Matt PinkstonAuthor Commented:
Rob H, like your solution but am getting a lot of

#NA and I would like this to say No Rating
0
 
Rob HensonIT & Database AssistantCommented:
It could be the placing of brackets, I typed the formula, on the hoof as they say, rather than copying.

I am away from desk now but will take a look when get chance
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now