Re: Match Data From 2 Worksheet
Hi,
I tried but the result now is wrong. I think the first one is better, it just had those 2 blank fields at the starting. Never mind, I shall delete off those cells manually. Thanks for the help.
- Meena
Re: Match Data From 2 Worksheet
Hi,
I tried but the result now is wrong. I think the first one is better, it just had those 2 blank fields at the starting. Never mind, I shall delete off those cells manually. Thanks for the help.
- Meena
Re: Match Data From 2 Worksheet
Quote from meena88Hi,
I tried but the result now is wrong. I think the first one is better, it just had those 2 blank fields at the starting. Never mind, I shall delete off those cells manually. Thanks for the help.
- Meena
If it solve your problem, that will be OK, but are the result correct?
If not, I will rewrite the code.
Re: Match Data From 2 Worksheet
The first one u wrote, the result is correct, but just that there was a space in front. If the space is removed then it will be correct. The second one u wrote, the result was wrong.
Re: Match Data From 2 Worksheet
If you cant get what im trying to explain, please refer to this workbook. It shows what is the expected result, and what result is obtained after running the macro.
Re: Match Data From 2 Worksheet
try this anyway
Sub test()
Dim a(), i As Long, b, z As String
a = Sheets("Sheet1").Range("a1").CurrentRegion.Resize(,6).Value
ReDim Preserve a(1 To UBound(a,1), 1 To 8)
a(1,7) = "Country/ Area Supplier" : a(1,8) = "Division Trade Policy"
With CreateObject("ScriptingDictionary")
.CompareMode = vbTextCompare
For i = 1 To UBound(a,1)
z = a(i,1) & ";" & a(i,6)
If Not .exists(z) Then .add z, i
Next
b = Sheets("sheet2").Range("a1").CurrentRegion.Resize(,8).Value
For i = 2 To UBound(b,1)
z = b(i,5) & ";" & b(i,1)
If .exists(z) Then
a(.item(z), 7) = b(i,6) : a(.item(z), 8) = b(i,8) '<- check this part for the right column
End If
Next
End With
With Sheets("result").Range("a1")
.CurrentRegion.ClearContents
.Resize(UBound(a,1), UBound(a,2)).Value = a
End With
End Sub
Display More
Re: Match Data From 2 Worksheet
Hiiii,
Wowww...coool...Its working perfectly great! The space is gone and with the correct results. Thanks a lotttt!!! Your help has made my work faster, really appreciating it.
Meena
Don’t have an account yet? Register yourself now and be a part of our community!