Using an example from MSDN I'm trying to set the value of a cell in Excel 2007. Here are the steps I took:
- In the Excel options choose
Enable all Macro'sandTrust access to VBA object model. - Create a new Excel WorkBook.
- Add a new VBA Module.
Insert the following function:
Function MyTest(rg As Range) rg.Value = 1 MyTest = 1234 End FunctionAdd the formula
=MyTest(B1)to the cell at A1.
When the first line of MyTest is executed, the debugger simple fails. Without any error it stops debugging and displays #VALUE! in A1. B1 remains empty.
I've tried setting .Formula instead of .Value. I've tried using ActiveSheet and Worksheets["Sheet1"] to access Worksheets. What can possibly be the cause of this error?
rg? What happens when you comment out that line?rg.Formula = 1, A1 changes to 1234 as expected. I try to set rg because I want to change cells programmatically.