Sub test()
Dim a, result(), i As Long, z As String, n As Long, ws As Workbook
a = ThisWorkbook.Sheets(1).Range("a1").CurrentRegion.Resize(,2).Value
ReDim result(1 To UBound(a,1), 1 To 2)
With CreateObject("Scripting.Dictionary")
.CompareMode = vbTextCompare
For i = 2 To UBound(a,1)
If Not IsEmpty(a(i,1)) Then
z = Left(a(i,1),2)
If Not .exists(z) Then
n = n + 1
result(n,1) = z
result(n,2) = a(i,2)
Else
x = .item(z)
If InStr(1,result(x,2),"High",vbTextCompare) = 0 Then
If InStr(1,a(i,2),"High",vbTextCompare) > 0 Then
result(x,2) = a(i,2)
ElseIf InStr(1, a(i,2), "Med",vbTextCompare) > 0 Then
result(x,2) = a(i,2)
End If
End If
End If
End If
Next
For Each ws In Workbooks
If wb.Name <> ThisWorkbook.Name Then
With wb.Sheets(1)
For Each r In .Range("a2",.Range("a" & Rows.Count).End(xlUp))
If .exists(r.Value) Then r.Offset(,1) = .item(r.Value)
Next
End With
End If
Next
End With
End Sub
Sub test()
Dim a, result(), i As Long, z As String, n As Long, ws As Workbook
a = ThisWorkbook.Sheets(1).Range("a1").CurrentRegion.Resize(, 2).Value
ReDim result(1 To UBound(a, 1), 1 To 2)
With CreateObject("Scripting.Dictionary")
.CompareMode = vbTextCompare
For i = 2 To UBound(a, 1)
If Not IsEmpty(a(i, 1)) Then
z = Left(a(i, 1), 2)
If Not .exists(z) Then
n = n + 1
result(n, 1) = z
result(n, 2) = a(i, 2)
Else
x = .Item(z)
If InStr(1, result(x, 2), "High", vbTextCompare) = 0 Then
If InStr(1, a(i, 2), "High", vbTextCompare) > 0 Then
result(x, 2) = a(i, 2)
ElseIf InStr(1, a(i, 2), "Med", vbTextCompare) > 0 Then
result(x, 2) = a(i, 2)
End If
End If
End If
End If
Next
For Each ws In Workbooks
If ws.Name <> ThisWorkbook.Name Then
With ws.Sheets(1)
For Each r In .Range("a2", .Range("a" & Rows.Count).End(xlUp))
If .exists(r.Value) Then r.Offset(, 1) = .Item(r.Value)
Next
End With
End If
Next
End With
End Sub
If .exists(r.Value) Then r.Offset(, 1) = .Item(r.Value)
Sub test()
Dim a, result(), i As Long, z As String, n As Long, ws As Workbook, r As Range
a = ThisWorkbook.Sheets(1).Range("a1").CurrentRegion.Resize(,2).Value
ReDim result(1 To UBound(a,1), 1 To 2)
With CreateObject("Scripting.Dictionary")
.CompareMode = vbTextCompare
For i = 2 To UBound(a,1)
If Not IsEmpty(a(i,1)) Then
z = Left(a(i,1),2)
If Not .exists(z) Then
n = n + 1
result(n,1) = z
result(n,2) = a(i,2)
Else
x = .item(z)
If InStr(1,result(x,2),"High",vbTextCompare) = 0 Then
If InStr(1,a(i,2),"High",vbTextCompare) > 0 Then
result(x,2) = a(i,2)
ElseIf InStr(1, a(i,2), "Med",vbTextCompare) > 0 Then
result(x,2) = a(i,2)
End If
End If
End If
End If
Next
For Each ws In Workbooks
If wb.Name <> ThisWorkbook.Name Then
With wb.Sheets(1)
For Each r In .Range("a2",.Range("a" & Rows.Count).End(xlUp))
If .exists(r.Value) Then r.Offset(,1) = result(.item(r.Value,2)
Next
End With
End If
Next
End With
End Sub
Sub sample()
Dim ws1 As Worksheet, ws2 As Worksheet, r As Range, c As Range, ff As String, myStatus As String
Set ws1 = Workbooks("Example1.xls").Sheets("Sheet1")
Set ws2 = Workbooks("Example2.xls").Sheets("Sheet1")
For Each r In ws2.Range("b2",ws2.Range("b" & Rows.Count).End(xlUp))
Set c = ws1.Columns("a").Find(r.Value,,,xlPart)
If Not c Is Nothing Then
ff = c.Address
Do
Select Case c.Offset(,1).Value
Case "*High" : myStatus = "Risk-High" : Exit Do
Case "*Med" : myStatus = "Risk-Med"
Case "*Low"
If myStatus <> "Risk-High" And myStatus <> "Risk-Med" Then
myStatus = "Risk-Low"
End If
End Select
Set c = ws1.columns("a").FindNext(c)
Loop Until ff = c.Address
r.Offset(,6).Value = myStatus : myStatus = Empty
Else
MsgBox r.Value & " is not exist"
End If
Next
Set ws1 = Nothing
Set ws2 = Nothing
End Sub