Index match VBA

anand3dinesh

Board Regular
Joined
Dec 19, 2019
Messages
137
Office Version
  1. 365
Platform
  1. Windows
Hi i'm a beginner can you please help me to wright VBA script for "Index match" that returns value from other worksheet?
please refer images i have 2 worksheets a and B in sheet b i need code that fills cells according to the column heading
 

Attachments

  • Sheet a.PNG
    Sheet a.PNG
    6.3 KB · Views: 11
  • Sheet b.PNG
    Sheet b.PNG
    3.8 KB · Views: 10

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
assuming your column headers are in A1:D1, why cant you just go to Sheet B in cell B2 and put =VLOOKUP(A2,'sheet a'!$A$2:$D$11,2,FALSE) ?
 
Upvote 0
i know Vlookup and Index Match functions, i am trying to learn VBA Script
assuming your column headers are in A1:D1, why cant you just go to Sheet B in cell B2 and put =VLOOKUP(A2,'sheet a'!$A$2:$D$11,2,FALSE) ?
 
Upvote 0
How about
Rich (BB code):
Sub anand3dinesh()
    With Sheets("Sheet2")
        With .Range("B2:B" & .Range("A" & Rows.Count).End(xlUp).Row)
            .Formula = "=INDEX(Sheet1!$B$2:$D$9,MATCH($A2,Sheet1!$A$2:$A$9,0),MATCH(B$1,Sheet1!$B$1:$D$1,0))"
            .Value = .Value
        End With
    End With
End Sub
change sheet names in red to suit.
Remove the line in blue if you want to keep the formula
 
Upvote 0
How about
Rich (BB code):
Sub anand3dinesh()
    With Sheets("Sheet2")
        With .Range("B2:B" & .Range("A" & Rows.Count).End(xlUp).Row)
            .Formula = "=INDEX(Sheet1!$B$2:$D$9,MATCH($A2,Sheet1!$A$2:$A$9,0),MATCH(B$1,Sheet1!$B$1:$D$1,0))"
            .Value = .Value
        End With
    End With
End Sub
change sheet names in red to suit.
Remove the line in blue if you want to keep the formula
Hi thank you for the code, when i run i throw Run Time error.
it says Subscript out of range
 
Upvote 0
Did you change the sheet names?
 
Upvote 0

Forum statistics

Threads
1,214,965
Messages
6,122,500
Members
449,090
Latest member
RandomExceller01

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