VBA Code for INDEX and MATCH – multiple criteria and multiple results

zjghazal

New Member
Joined
Mar 24, 2022
Messages
2
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
I have a table of multiple agents per country with their contact information I need to extract name and contact information of all available agents of the country name in F2 to G,H, and I columns from A,B,C, and D Table

My Macro is extracting the same Data.

My Macro code

Sub Get_Agent_Info()

Dim i As Integer
Dim lr As Integer
Dim namecol As Range
Dim Emailcol As Range
Dim Ctcol As Range
Dim cocol As Range
Dim Country As Range

lr = Cells(Rows.count, 2).End(xlUp).Row

Set cocol = Range("A2:A" & lr)
Set namecol = Range("B2:B" & lr)
Set Emailcol = Range("C2:C" & lr)
Set Ctcol = Range("D2:D" & lr)
Set Country = Range("$F$2")

For i = 2 To lr

On Error Resume Next

Cells(i, 7).Value = Application.WorksheetFunction.Index(namecol, Application.WorksheetFunction.match(Country, cocol, 0))
Cells(i, 8).Value = Application.WorksheetFunction.Index(Emailcol, Application.WorksheetFunction.match(Country, cocol, 0))
Cells(i, 9).Value = Application.WorksheetFunction.Index(Ctcol, Application.WorksheetFunction.match(Country, cocol, 0))

Next

End Sub



I hope this helps I attached a Screen shot too

Thank you
Zak
 

Attachments

  • Screen Shot of the Table.png
    Screen Shot of the Table.png
    50.9 KB · Views: 15

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Hi & welcome to MrExcel.
Why not just use a formula
Excel Formula:
=FILTER(B2:D100,A2:A100=F2)
 
Upvote 0
Hi & welcome to MrExcel.
Why not just use a formula
Excel Formula:
=FILTER(B2:D100,A2:A100=F2)
I have other Macros running based on the results; where to plug above formula sorry I am a novice in VB
 
Upvote 0
You can out that in G2 after clearing all the cells in columns G, H & I from row 2 down.
 
Upvote 0

Forum statistics

Threads
1,214,583
Messages
6,120,377
Members
448,955
Latest member
BatCoder

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