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 Type "Mismatch": How construct a formula from cells with formulas as text?

Sub RestoreFormulas ()
Dim cell as Range
for each cell in Sheet118.Range("C29:G48")
cell.Formula = "=" & Sheet203.Range(c.Address)
Next

End Sub

or

Sheet118.Range("C29:G48").Value = Sheet203.Range("C29:G48").Value
for each cell in sheet203.Range("C29:G48")
cell.Formula = "=" & cell.Value
Next

You might be able to use the Replace method to avoid the loop, but that
would presuppose a common unique starting string for each formula.

--
Regards,
Tom Ogilvy


--
Regards,
Tom Ogilvy


wrote in message
...
Tank you, your suggestion works fine in test. When I make a application of
this, Iget error 13, "type mismatch". In the excel sheets, I actually have
copy - pasted the cells so they should be the same type. The only thing I
have done is deleted the "=" before the formulas.

Sub RestoreFormulas ()
Sheet118.Range("C29:G48").Cells.Formula = "=" &
Sheet203.Range("C29:G48").Cells.Value
End Sub

A typical template formula in one cell is: NkSc2!$D$29-NkSc1!$D$29
but that doesn't matter, I guess.

My question is open to anybody who can answer.

/Regards

"Simon Murphy" skrev i meddelandet
...
Can you do something like:
newcell.formula = "=" & templatecell.value (or .formula)?

cheers
Simon

-----Original Message-----
I got a template sheet containing "formulas as text" (I

have just wiped away
the "=" and formated the cells as text)

In another sheet I want to puzzel it together again as

real formulas - I
need to put an "=" and the "formulas as text"

In the template sheet here called Sheet2:
Sheet20.Range("A1:A2") A1: ShtX!$C$29-ShtY!$C$29
A2: ShtX!$C$30-

ShtY!$C$30

In Sheet1, where I want to have the formulas visual and

working. I want the
result to be the products from the newborn formulas and

the formulas visual
just as an ordinary formula in a cell use to.

Like if i would have written:
A1: = ShtX!$C$29-ShtY!$C$29
A2: = ShtX!$C$30-ShtY!$C$30

Easy but complex to describe, maybe? instead of writing

the formula, I want
to create it from a "template" with the formula

I'm sure this is easy to do, but I've tried several ways

know without
success.

/Regards


.