Search sheet 1 and update the summar in sheet 2

nianchi111

Board Regular
Joined
Aug 24, 2007
Messages
197
Office Version
  1. 365
HI All,

I have 2 sheets in an excel.

take the first name in the sheet 1 and search in sheet 2 and based on the country from and to update in the "1" in the sheet 1 under the respective contries.

In sheet 2 there would be multiple entries so it has to search for all the data and update in sheet 1, once this is done it has to take the next name is sheet 1 and do the same.


In sheet 1 I want a summary of this like below


USACanadaIranMexicoPakistanIndia
Vimal
1​
1​
1​
1​
1​
Kumar
1​
1​
1​
1​
1​

Sheet 2 - has the list of data of people who travelled to different countries

NameFromTo
VimalIndiaUSA
VimalCanadaIran
VimalIranMexico
KumarCanadaMexico
KumarMexicoUSA
KumarUSACanada
KumarIndiaPakistan

Thanks,
Vimal Vikraman
 
There is, but I don't have time at the moment.
If nobody else jumps in, I'll have a look tomorrow.
 
Upvote 0

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Ok, how about
VBA Code:
Sub nianchi()
   Dim Ary As Variant, Nary As Variant
   Dim r As Long, c As Long
   
   Ary = Sheets("Sheet2").Range("A1").CurrentRegion.Value2
   Nary = Sheets("Sheet1").Range("A1").CurrentRegion.Value2
   
   With CreateObject("scripting.dictionary")
      For r = 2 To UBound(Ary)
         .Item(Ary(r, 1)) = .Item(Ary(r, 1)) & "|" & Ary(r, 2) & "|" & Ary(r, 3)
      Next r
      For r = 2 To UBound(Nary)
         For c = 2 To UBound(Nary, 2)
            If InStr(1, .Item(Nary(r, 1)), Nary(1, c), vbTextCompare) Then Nary(r, c) = 1
         Next c
      Next r
   End With
   Sheets("Sheet1").Range("A1").CurrentRegion.Value = Nary
End Sub
 
Upvote 0
Solution
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,036
Messages
6,122,794
Members
449,095
Latest member
m_smith_solihull

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top