View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default How to set a formula in a cell? Application-defined error.

Assuming Table S is another workbook.

Public Sub InsertLinkedTableTitle()
'This macro links the suppl table title in draft
'indicators to the CODE box of form
Dim RA As Range
Set RA = ActiveSheet.Range("A1")
RA.Formula = "='[Table S.xls]Title Page'!D2"
End Sub

Don't use FormulaR1C1 if you are going to use A1 style addressing.

--
Regards,
Tom Ogilvy


"John Wirt" wrote in message
...
Here is the beginning of a procedure I wrote to enter a formula in a cell
that links the cell to a value in some other cell. When I run this
procedure, I get a 1004 error: "Application-defined or obejct-defined

error"
at the last statement.

Public Sub InsertLinkedTableTitle()
'This macro links the suppl table title in draft
'indicators to the CODE box of form
Dim RA As Range
Set RA = ActiveSheet.Range("A1")
RA.FormulaR1C1 = "='Table S' &'Title Page'!D2"
End Sub

The problem is the 'Table S' part of the formula. If I take it (and the

'&")
out of the formula, the procedure runs fine. There is something I don't

know
about formatting such a text string in a formula.

JOhn Wirt