VBA Index Match (Error Handling)

ElRoober

New Member
Joined
Feb 11, 2024
Messages
6
Office Version
  1. 365
Platform
  1. Windows
Hello Everyone,

I am a super basic vba user. I was wondering if someone would be able to show me how to adjust the code below to return the value "No Data" if a value is not there and to continue rather than throwing an error.

Thanks you so much :)


Sub IndexMatch()

Dim i As Integer

'Perform index match
For i = 2 To 11
Cells(i, 6).Value = WorksheetFunction.Index(ThisWorkbook.Worksheets("sheet1").Range("A2:A11"), _
WorksheetFunction.Match(Cells(i, 4).Value, ThisWorkbook.Worksheets("sheet1").Range("B2:B11"), 0))

Next i

End Sub
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Here's an alternative method to try:
VBA Code:
With Range("F2:F11")
    .FormulaR1C1 = "=IFERROR(INDEX(R2C1:R11C1,MATCH(RC4,R2C2:R11C2,0)),""No Data"")"
    .Value = .Value
End With
 
Upvote 0
Here's an alternative method to try:
VBA Code:
With Range("F2:F11")
    .FormulaR1C1 = "=IFERROR(INDEX(R2C1:R11C1,MATCH(RC4,R2C2:R11C2,0)),""No Data"")"
    .Value = .Value
End With
Hi thanks for getting back to me with this solution. Is there aways to amend it to reflect my range being on another sheet (sheet 1). Thank you again.
 
Upvote 0
Certainly:
VBA Code:
With Range("F2:F11")
    .FormulaR1C1 = "=IFERROR(INDEX('Sheet1'!R2C1:R11C1,MATCH(RC4,'Sheet1'!R2C2:R11C2,0)),""No Data"")"
    .Value = .Value
End With
 
Upvote 0
Solution
Certainly:
VBA Code:
With Range("F2:F11")
    .FormulaR1C1 = "=IFERROR(INDEX('Sheet1'!R2C1:R11C1,MATCH(RC4,'Sheet1'!R2C2:R11C2,0)),""No Data"")"
    .Value = .Value
End With
Works a charm! thank you so much for this; a massive help.
 
Upvote 0

Forum statistics

Threads
1,224,813
Messages
6,181,114
Members
453,021
Latest member
Justyna P

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