ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   How to use VLOOKUP to copy range to another workbook? (https://www.excelbanter.com/excel-discussion-misc-queries/79831-how-use-vlookup-copy-range-another-workbook.html)

UNISON Issy

How to use VLOOKUP to copy range to another workbook?
 
I want to search for a match to an identifier in Column A of Sheet1. If
found, copy the whole of the associated row to Sheet2, where other columns
will be added after the copied data. If not found, return a "Not found"
message. There could be up to 12000 rows in main worksheet. Relatively
novice user so nothing too complicated, please!

Toppers

How to use VLOOKUP to copy range to another workbook?
 
Hi,
A starter. It assumes your Identifier is TEXT

Sub GetMatch(ByVal MatchKey As String, ByVal MatchRng As Range)
res = Application.Match(MatchKey, MatchRng, 0)
If IsError(res) Then
MsgBox " No match found for " & MatchKey
Else
Worksheets("Sheet1").Cells(res, "A").EntireRow.Copy _
Worksheets("sheet2").Cells(Rows.Count, "A").End(xlUp)(2)
End If
End Sub


Sub test()
Set rng = Worksheets("Sheet1").Range("A1:a12000") '<=== Change to suit but
start at A1
' Add a loop to go through your ID s
Call GetMatch("5", rng)
End Sub


HTH

"UNISON Issy" wrote:

I want to search for a match to an identifier in Column A of Sheet1. If
found, copy the whole of the associated row to Sheet2, where other columns
will be added after the copied data. If not found, return a "Not found"
message. There could be up to 12000 rows in main worksheet. Relatively
novice user so nothing too complicated, please!



All times are GMT +1. The time now is 08:56 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com