Одним из возможных решений является функция VLOOKUP
:
Лист 3
- Формула столбца B (импортируйте формулу в ячейку B6 и перетащите ее вниз):
=VLOOKUP(A6,Sheet4!$A$1:$F$5000,3,0)
- Столбец C формула (импортируйте формулу в ячейку C6 и перетащите ее вниз):
=VLOOKUP(A6,Sheet4!$A$1:$F$5000,6,0)
Код VBA:
Option Explicit
Sub tes()
Dim ws3 As Worksheet, ws4 As Worksheet
Dim i As Long
Dim rngSearch As Range, rngFound As Range
Dim arr As Variant
Dim strValueC As String, strValueF As String
With ThisWorkbook
Set ws3 = .Worksheets("Sheet3")
Set ws4 = .Worksheets("Sheet4")
End With
With ws3
arr = .Range("A6:A33")
.Range("B6:C33").Clear
End With
Set rngSearch = ws4.Range("A1:A5000")
For i = LBound(arr) To UBound(arr)
Set rngFound = rngSearch.Find(What:=arr(i, 1), LookIn:=xlValues, LookAt:=xlWhole)
If Not rngFound Is Nothing Then
With ws4
strValueC = .Range("C" & rngFound.Row).Value
strValueF = .Range("F" & rngFound.Row).Value
End With
With ws3
.Range("B" & i + 5).Value = strValueC
.Range("C" & i + 5).Value = strValueF
End With
End If
Next i
End Sub