VBA formula not working

texasalynn

Well-known Member
Joined
May 19, 2002
Messages
8,458
I've been staring at this for an hour and can't find the problem.

Code:
Set rngFound = Cells.Find(What:=MyData, After:=ActiveCell, _
    LookAt:=xlPart, MatchCase:=True)
    f = rngFound.Address
    df = "'" & ShName & "'!" & f
Worksheets(ShName2).Activate
    Range("A2").FormulaR1C1 = _
        "=RIGHT(" & df & ")"

The line Range("A2")... gets an error application-defined or object-defined error. What am I missing here?
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
You're not entering a R1C1 formula, yet you are using the FormulaR1C1 property.

Change FormulaR1C1 to simply Formula.

Edit: You also should not need to select the sheet. This should enter the formula just the same:
Code:
Worksheets(ShName2).Range("A2").Formula = "=RIGHT(" & df & ")"
 
Upvote 0
Aren't you missing the 2nd argument for RIGHT?
 
Upvote 0
could be, but the real problem was what Von Pookie suggested. I didn't post my full code, only a portion so I may have left it off. But all is working correctly now. Thanks for the pointer
 
Upvote 0
Aren't you missing the 2nd argument for RIGHT?

Technically not, at least if the object is to return only one character. Anymore than that, then yes, the 2nd argument is missing. :)
 
Upvote 0
Von Pookie

:oops:

I just realised that when I checked back.
 
Upvote 0

Forum statistics

Threads
1,207,423
Messages
6,078,443
Members
446,338
Latest member
AliB

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