VBA Index Match on a table help

JashVash

New Member
Joined
Feb 23, 2022
Messages
18
Office Version
  1. 365
Platform
  1. Windows
Hello,

I am trying to do an index match from one sheet to the other I am unsure of what I am doing wrong, nothing is populating when I run the code and there are no syntax errors.

I have Sheets("IFS Upload") Referencing to a table from another sheet named Sheets("Category")

My code is shown below and the references I am trying to index match, am I missing a step?
Do I need to also define where the table is?
Please help me.



VBA Code:
Dim Ifs As Worksheet
Dim LastRow As Long
Dim Category As Integer

Set Ifs = ThisWorkbook.Sheets("IFS Upload")

LastRow = Cells(Rows.Count, 1).End(xlUp).Row
    
For x = 2 To LastRow
    On Error Resume Next
    If Len(Ifs.Range("N" & x).Value) > 0 Then
     Ifs.Range("O" & x) = WorksheetFunction.Index(Range("jobtype[Trade]"), WorksheetFunction.Match("N" & x, Range("jobtype[IFS]"), 0))
   
    
End If

Next x

1655388793050.png

1655388836902.png
 

Attachments

  • 1655388691087.png
    1655388691087.png
    24.7 KB · Views: 3
  • 1655388697966.png
    1655388697966.png
    24.7 KB · Views: 5

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
The reason you are not getting an error is because your On Error Resume Next is masking it.

Change your formula line to the below:
The change is putting you "N" & x inside of Range()

VBA Code:
         Ifs.Range("O" & x) = WorksheetFunction.Index(Range("jobtype[Trade]"), WorksheetFunction.Match(Range("N" & x), Range("jobtype[IFS]"), 0))
 
Upvote 0
The reason you are not getting an error is because your On Error Resume Next is masking it.

Change your formula line to the below:
The change is putting you "N" & x inside of Range()

VBA Code:
         Ifs.Range("O" & x) = WorksheetFunction.Index(Range("jobtype[Trade]"), WorksheetFunction.Match(Range("N" & x), Range("jobtype[IFS]"), 0))
Thank you Alex,

I have tried and removed the on error. But I am getting this error now, Do you know if I have to define the work sheet where the table is?

1655391548012.png
 
Upvote 0
No you don't.
What you need is some code that handles the error of not finding a match.
I have logged off for the night but can do it tomorrow.
 
Upvote 0
No you don't.
What you need is some code that handles the error of not finding a match.
I have logged off for the night but can do it tomorrow.
Thank you Alex I appreciate your help! Have a good night! Looking forward to your help tomorrow! Cheers!
 
Upvote 0
See if this works for you.

VBA Code:
        With Application
            Ifs.Range("O" & x) = .IfError(.Index(Range("jobtype[Trade]"), .Match(Range("N" & x), Range("jobtype[IFS]"), 0)), "")
        End With

Using WorksheetFunction gives you access to Intellisense but removing it and relying on Application. allows you to use normal error handling (IfError or IsError) as opposed to having to handle VBA errors (On Error)
 
Upvote 0
Solution
See if this works for you.

VBA Code:
        With Application
            Ifs.Range("O" & x) = .IfError(.Index(Range("jobtype[Trade]"), .Match(Range("N" & x), Range("jobtype[IFS]"), 0)), "")
        End With

Using WorksheetFunction gives you access to Intellisense but removing it and relying on Application. allows you to use normal error handling (IfError or IsError) as opposed to having to handle VBA errors (On Error)
Thank you Alex I figured it out it was referencing the wrong reference. and Managed to get it to work! Thank you so much for your help!!! I appreciate it!
Hope you have a good one!
 
Upvote 0

Forum statistics

Threads
1,214,994
Messages
6,122,633
Members
449,092
Latest member
bsb1122

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