Iferror index and match formula in VBA

A Thayuman

New Member
Joined
Mar 6, 2019
Messages
28
Book1
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACAD
1QTYItem NumberDescription PriceUnitDisc %Total
2 EL-PL24W0612A 24W LED Panel Light 600x1200mm $ 30.00  
3 #N/A  
4 #N/A  
5
6
7The idea of using Index and match in VBA is so that I can overwirte the description when needed without having to worry about deleting the formula.
8Data Validation TableFormula is rewirtten when the sheet is opend for use again
9However when:
10Item Number Description
11EL-PL36W0612A36W LED Panel Light 600x1200mmThis Code "=INDEX($E$11:$E15,MATCH(C2, $C$11:$C$15, 0))" inbeds in the cell I choose, it works fine when activated on opening the sheet by VBA: =INDEX($Z$3:$Z$30,MATCH(C2, $W$3:$W$30, 0))
12EL-PL24W0612A 24W LED Panel Light 600x1200mmHowerver when Cell "C" has no information the "F2" shows #N/A
13EL-PL24W0312A 24W LED Panel Light 300x1200mm
14EL-PL24W0606A24W LED Panel Light 600x600mmThis formula pasted as a code in VBA does not work at all "=IFERROR(=INDEX($E$11:$E15,MATCH(C2, $C$11:$C$15, 0))," ")"
15EL-PL12W0306A 12W LED Panel Light 300x600mmAnd a message window pops up with "Complie Error, Expected: End Statement
16
17
18
Sheet1
Cell Formulas
RangeFormula
F2:F4F2=INDEX($E$11:$E15,MATCH(C2, $C$11:$C$15, 0))
M3:M4M3=IFERROR(INDEX($AA$3:$AA$30,MATCH(C3, $W$3:$W$30, 0))," ")
O3:O4O3=IFERROR(INDEX($AB$3:$AB$30,MATCH(C3, $W$3:$W$30, 0))," ")
S2:S4S2=IFERROR((A2*M2) -(A2*M2*Q2),0)
Cells with Conditional Formatting
CellConditionCell FormatStop If True
C15:D15,C11:D13Cell ValueduplicatestextNO
Cells with Data Validation
CellAllowCriteria
C2:E4List=$C$11:$C$15
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Hi,
In order, as you say, "to paste the formula in VBA"... you do need to use Evaluate
i.e. Evaluate("yourformula")
 
Upvote 0
You would need to double-up on the quotes inside the formula like
VBA Code:
"=IFERROR(=INDEX($E$11:$E15,MATCH(C2, $C$11:$C$15, 0)),"""")"
 
Upvote 0
Hi,
In order, as you say, "to paste the formula in VBA"... you do need to use Evaluate
i.e. Evaluate("yourformula")
Hi Thanks for getting back to me I tried using evaluate as seen below and it does nothing - I get no errors in the VBA message box either

Sub iferror()


Evaluate Range("F2") = "=IFERROR(=INDEX($E$11:$E15,MATCH(C2, $C$11:$C$15, 0)),"""")"


End Sub
 
Upvote 0
You would need to double-up on the quotes inside the formula like
VBA Code:
"=IFERROR(=INDEX($E$11:$E15,MATCH(C2, $C$11:$C$15, 0)),"""")"
Range("F2") = "=IFERROR(=INDEX($E$11:$E15,MATCH(C2, $C$11:$C$15, 0)),"""")"
I get run time error '1004': application defined n or object defined error

Thanks for your offer to help
 
Upvote 0
Hi,
You could test:
VBA Code:
Sub TestError()
   Range("F2") = Evaluate("=IFERROR(=INDEX($E$11:$E15,MATCH(C2, $C$11:$C$15, 0)),"""")")
End Sub
 
Upvote 0
Hi,
You could test:
VBA Code:
Sub TestError()
   Range("F2") = Evaluate("=IFERROR(=INDEX($E$11:$E15,MATCH(C2, $C$11:$C$15, 0)),"""")")
End Sub
When I copied and pasted the code I got #VALUE! not the formula in the cell

Thanks again for helping out, regards Anil
 

Attachments

  • Iferror Code and Excel sheet Value.JPG
    Iferror Code and Excel sheet Value.JPG
    117.4 KB · Views: 12
Upvote 0
Apparently you seem to be working with Merged Cells ...

Merged Cells are a total disaster ...!!!:mad: and preventing you from working with Excel ...(n)

Just get rid of them ...
 
Upvote 0
Didn't notice you had an extra = sign in the formula, you need to get rid of it
Excel Formula:
Range("F2").formula="=IFERROR(INDEX($E$11:$E15,MATCH(C2, $C$11:$C$15, 0)),"""")"
 
Upvote 1
Solution
Didn't notice you had an extra = sign in the formula, you need to get rid of it
Excel Formula:
Range("F2").formula="=IFERROR(INDEX($E$11:$E15,MATCH(C2, $C$11:$C$15, 0)),"""")"
Hi Fluff thanks works perfectly thanks for your help
 
Upvote 0

Forum statistics

Threads
1,214,919
Messages
6,122,260
Members
449,075
Latest member
staticfluids

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