FormulaR1C1 not working when using UserInterFaceOnly:=True

alibini

New Member
Joined
Mar 15, 2020
Messages
27
Office Version
  1. 365
Platform
  1. Windows
Hi I am trying to run some macros in a protected sheet.
I believe using the UserInterFaceOnly:=True method will allow this and i have it in my Workbook_Open macro.

But a simple operation of copying a relative formula does not work.
Setup code:

VBA Code:
Private Sub Workbook_Open()

Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets

ws.Protect Password:="abc", userinterfaceonly:=True

Next ws

End Sub

The simple following code will then work when sheet is unlocked but fails when locked on the FormulaR1C1 line.
It seems .Value works but .Formula doesn't.
Cell H16 should end up with the formula "=B3".
I'm open to solutions or better approaches.

VBA Code:
Sub PasteFormula()

Range("H15").Value = "=B2"
Range("H16").FormulaR1C1 = Range("H15").FormulaR1C1

End Sub
Thanks you so much all!
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
I just googled and found comments about similar unexpected behavior with UserInterfaceOnly.
Documentation explaining the rules/limits/ what you can/can't do I did not find.
Looks like you'll need to code an alternative approach.
I see someone's comments on similar situation in post #13 of this old thread Userinterfaceonly problem
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,154
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