reverse look up using vba macro (beginner)

alksndr

New Member
Joined
Jun 25, 2016
Messages
11
Hi,

would like to know how can I execute reverse look up or index match using vba macro?

My worksheet looks like this:

PHP:
Row      Column A       Column B       Column C       
  1        Process          Subprocess     Ref. Indicator
  2        Reporting       Statutory        FO/RM
  3        Reporting       Projects          FO/RP
  4        Reporting       Projects          FO/RPW
  5        Reporting       Projects          FO/RPB

So my look up value is in column C while my return value is in column A


Thank you guys for the help!
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Since the data to return is to the left of the data you're looking up, you need to use INDEX/MATCH:


Book1
ABCDEF
1ProcessSubprocessRef. IndicatorLookup Ref Value:FO/RPW
2ReportingStatutoryFO/RMProcess:Reporting
3ReportingProjectsFO/RP
4ReportingProjectsFO/RPW
5ReportingProjectsFO/RPB
Sheet1
Cell Formulas
RangeFormula
F2=INDEX($A$2:$A$5, MATCH($F$1, $C$2:$C$5, 0))


WBD
 
Upvote 0
Apology but I forgot to include this condition >> after determining the Process, macro should insert another column beside the lookup value

example:

Sheet1
PHP:
                       *lookupvalue    *insert
                                       returnvalue
Row      Column A       Column B       Column C       Column D       
  1      Emp ID         Ref Indicator  Process        MLA-DEL
  2      PHMABI         FO/RM          Reporting      MLA-DEL
  3      PHMABC         FO/RP          Reporting      MLA-DEL
  4      PHACBV         FO/RPW	       Reporting      MLA-DEL

Sheet 2
PHP:
Row      Column A       Column B       Column C        
  1      Process        Subprocess     Ref. Indicator 
  2      Reporting      Statutory      FO/RM 
  3      Reporting      Projects       FO/RP 
  4      Reporting      Projects       FO/RPW 
  5      Reporting      Projects       FO/RPB



Hi,

would like to know how can I execute reverse look up or index match using vba macro?

My worksheet looks like this:

PHP:
Row      Column A       Column B       Column C       
  1        Process          Subprocess     Ref. Indicator
  2        Reporting       Statutory        FO/RM
  3        Reporting       Projects          FO/RP
  4        Reporting       Projects          FO/RPW
  5        Reporting       Projects          FO/RPB

So my look up value is in column C while my return value is in column A


Thank you guys for the help!
 
Upvote 0
C2 formula in Sheet 1:

=INDEX(Sheet2!$A$2:$A$5, MATCH($B2, Sheet2!$C$2:$C$5, 0))

Then copy the formula down.

WBD
 
Upvote 0
Hi WBD,

Thank you for the quick reply!

But I'm hoping that I could do this with macro so that I wouldn't have to do it manually. any idea would be great. thanks!



C2 formula in Sheet 1:

=INDEX(Sheet2!$A$2:$A$5, MATCH($B2, Sheet2!$C$2:$C$5, 0))

Then copy the formula down.

WBD
 
Upvote 0
Code:
Public Sub ReverseLookup()

Dim lastRow As Long
Dim rowLoop As Long

lastRow = Sheets(1).Range("A" & Sheets(1).Rows.Count).End(xlUp).Row
If Sheets(1).Range("C1").Value <> "Process" Then
    Sheets(1).Columns(3).Insert
    Sheets(1).Range("C1").Value = "Process"
End If

Sheets(1).Cells(2, 3).Resize(lastRow - 1).Formula = "=INDEX('" & Sheets(2).Name & "'!A:A, MATCH(B2, '" & Sheets(2).Name & "'!C:C, 0))"

End Sub

WBD
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,912
Members
452,366
Latest member
TePunaBloke

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