Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why do apostrophies appear in cell?

Status
Not open for further replies.

RandySS

Technical User
Dec 7, 2009
20
US
Hi Folks,
Below subroutine seems to create the desired formula okay. However, when formula is written to target cell apostrophies seem to have been inserted, making the formula non-functional.

Desired formula is: =Sum(F1:F5)
Inserted formula is: =Sum('F1':'F5')

How do I build VB code such that apostrophies won't be inserted?

Thanks!
Randy

Sub WriteFormula()

Dim BottomCellAddress
Dim TopCellAddress
Dim SumField

TopCellAddress = Cells(1, 6).Value
BottomCellAddress = Cells(5, 6).Value
SumField = "=Sum(F" & TopCellAddress & ":F" & BottomCellAddress & ")" 'Yields: =Sum(F1:F5)

Range("G1").Select
ActiveCell.FormulaR1C1 = SumField
End Sub
 
Replace this:
ActiveCell.FormulaR1C1 = SumField
with this:
ActiveCell.Formula = SumField

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top