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!

Extra character (') in dynamically generated formula

Status
Not open for further replies.

jawbonium

Technical User
Nov 5, 2003
9
US
I am baffled. I am writing a macro to write the same forumla in the same cell in every sheet in my workbook except Summary (since the formula references the Summary sheet). Here is the script:

For Each ws In ActiveWorkbook.Worksheets
If (Not (ws.name = "Summary")) Then
ws.Cells(firstEmptyRow, 1).FormulaR1C1 = "=IF(Summary!A" _
& CStr(firstEmptyRow) _
& " > 0,Summary!A" _
& CStr(firstEmptyRow) _
& "," _
& Chr(34) _
& Chr(34) _
& ")"
End If
Next

But here is what is getting written:

=IF(Summary!'A177' > 0,Summary!'A177',"")

The four extra apostrophes are rendering the formula invalid. Any thoughts on how to be rid of them?
 
You're not using any R1C1 references, so just change FormulaR1C1 to Formula

For Each ws In ActiveWorkbook.Worksheets
If (Not (ws.name = "Summary")) Then
ws.Cells(firstEmptyRow, 1).Formula = "=IF(Summary!A" _
& CStr(firstEmptyRow) _
& " > 0,Summary!A" _
& CStr(firstEmptyRow) _
& "," _
& Chr(34) _
& Chr(34) _
& ")"
End If
Next
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top