Trouble with a Index Match formula in VBA

Stephenosn

Board Regular
Joined
Jun 2, 2015
Messages
52
Hello all,

I'm Trying to insert a line of code into a sheet's cell when a command button is pressed. I have three text boxes;tbMaterial, tbQty and tbCost. There a some materials that we use regularly so I already have their price listed (Ref_Cost). Other materials prices need to be entered manually. My intentions with the following line of code is to send the data from all three textboxes to my sheet if they are all used. If a price is not entered into tbCost I want to pass the following formula into the cell
Code:
=IFERROR(INDEX(Ref_UnitCost,MATCH(J2,Ref_Appliance,0))*AJ2,"")

Bellow is my attempt at the code.

Code:
If c.Offset(i - 1, 10) <> "" Then     c.Offset(i - 1, 36) = CCur(CDbl(c.Offset(i - 1, 10)) * c.Offset(i - 1, 35))
     If c.Offset(i - 1, 10) = "" Then
          c.Offset(-1, 36).FormulaR1C1 = "=INDEX(Ref_UnitCost,MATCH(1,(RC[-27]=Ref_Materials,Ref_Appliance,0)"
     End If 

End If

When the command button is pressed nothing is passed to the cell when the nested if statement is true.

Any idea what I've done wrong in my code?

Thank you for having a look,

John
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Hello all,

The following code solved my issue.

Code:
If c.Offset(i - 1, 10) <> "" Then                c.Offset(i - 1, 36) = CCur(CDbl(c.Offset(i - 1, 10)) * c.Offset(i - 1, 35))
            Else
                c.Offset(i - 1, 36).FormulaR1C1 = "=IFERROR(INDEX(Ref_UnitCost,MATCH(RC[-27],Ref_Appliance,0))*RC[-1],"""")"
            End If

Thanks for looking,

John
 
Upvote 0

Forum statistics

Threads
1,215,165
Messages
6,123,387
Members
449,098
Latest member
ArturS75

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