TropicalMagic
New Member
- Joined
- Jun 19, 2021
- Messages
- 47
- Office Version
- 365
- Platform
- Windows
Hi all,
I would like to check if row values in Workbooks("B.xlsx").Sheets(2).Range("AN2:AN" & LASTROW) can be found in Workbooks("A.xlsx").Sheets(1).Range("D1:D30"), then corresponding row values in Workbooks("B.xlsx").Sheets(2).Range("AM2:AM" & LASTROW) = "YES"
If row values cannot be found, then do nothing.
Here is my (non-functional) code so far:
Many thanks!
I would like to check if row values in Workbooks("B.xlsx").Sheets(2).Range("AN2:AN" & LASTROW) can be found in Workbooks("A.xlsx").Sheets(1).Range("D1:D30"), then corresponding row values in Workbooks("B.xlsx").Sheets(2).Range("AM2:AM" & LASTROW) = "YES"
If row values cannot be found, then do nothing.
Here is my (non-functional) code so far:
VBA Code:
Dim ws As Worksheet, ws2 As Worksheet
Dim j, LASTROW As Long
Dim arrD, arrFin As Variant
Dim answer, found As Range
Set ws = Workbooks("A.xlsx").Sheets(1)
Set ws2 = Workbooks("B.xlsx").Sheets(2)
LASTROW = ws2.Range("A" & Rows.Count).End(xlUp).Row
arrD = ws.Range("D1:D30").Value
ReDim arrFin(1 To UBound(arrD), 1 To 1)
For j = 1 To UBound(arrD)
answer = ws.Range("H" & j).Value
Set found = ws2.Columns("AN2:AN" & LASTROW).Find(what:=answer)
If found Is Nothing Then
Nothing
Else
arrFin(j, 1) = "YES"
End If
Next j
ws2.Range("AM2").Resize(UBound(arrFin), 1).Value = arrFin
Many thanks!