Compile error

asddsaasddas

Board Regular
Joined
Mar 23, 2020
Messages
60
Office Version
  1. 2016
  2. 2013
Platform
  1. Windows
I want to execute a function Via VBA. However i want to use the IFERROR command to change the value of the cell if my VLOOKUP returns #N/A. However i was faced with a compile error and i don't know how to fix it. I will be posting my code below for reference. Do let me know if there is a way to solve my problem or is there a better way to complete my action to achieve my desired outcome.

VBA Code:
Sub Find_Error()

iLastRow = Cells(Rows.Count, 1).End(xlUp).Row
Worksheets("incidents").Cells(2, 10).Formula = "=IFERROR(VLOOKUP(H2,Data,2,FALSE),"Error")"
Worksheets("incidents").Cells(2, 10).Copy
Range("j2:j" & iLastRow).Select
Selection.FillDown

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.
Any quotation marks that are part of the formula need to be doubled up:

Rich (BB code):
Worksheets("incidents").Cells(2, 10).Formula = "=IFERROR(VLOOKUP(H2,Data,2,FALSE),""Error"")"
 
Upvote 0
Any quotation marks that are part of the formula need to be doubled up:

Rich (BB code):
Worksheets("incidents").Cells(2, 10).Formula = "=IFERROR(VLOOKUP(H2,Data,2,FALSE),""Error"")"
Thank you very much for your reply! :)
 
Upvote 0
is there a better way to complete my action to achieve my desired outcome.
It seems to me that sheet "incidents" is the active sheet when you run this code?
If so, then a possible answer to the question I quoted is this single-line code

VBA Code:
Sub Find_Error()
  Range("J2:J" & Cells(Rows.Count, 1).End(xlUp).Row).Formula = "=IFERROR(VLOOKUP(H2,Data,2,FALSE),""Error"")"
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,788
Messages
6,121,600
Members
449,038
Latest member
Arbind kumar

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