object error/ formulaR1C1

minmark

New Member
Joined
Jul 18, 2016
Messages
44
I have record macro and rewrite them as following with loop:
DailyUsage:
Dim i As Integer, j As Integer


Range("J15").Select
For i = 4 To 34
ActiveCell.FormulaR1C1 = _
"=IF(ISERROR(MATCH(RC,Drug!C1,0)),"""",INDEX(Drug!C2,MATCH(RC,Drug!C1,0)))"




Cells(15, 7 + i).Select
Next i


But the message remind me error '1004' object define error ....(My operation system is Chinese traditional text, don't know exact English notice.)
How can I set the range with integer or other variables well in this case?

Thanks.
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Your variable, i, means something to the VBA code, but not to Excel. Therefore you need to pass only the value of i to Excel, like this:

Code:
ActiveCell.FormulaR1C1 = _
    "=IF(ISERROR(MATCH(RC[" & i & "],Drug!C1,0)),"""",INDEX(Drug!C2,MATCH(RC[" & i & "],Drug!C1,0)))"

You will be able to replace your loop with a single line of code:

Code:
Range("J15:AM15").Formula = ....

but I'm not sure what your intended formula is. Is it working as you envisage?

Also, if you have excel 2007 or later, you can replace the IF(ISERROR(YourFormula),"",YourFormula) with the simpler IFERROR(YourFormula,"")
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
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