Changing text to formula in a range of cells

B

Bob Arnett

I'm new in Excel having recently moved from another spreadsheet brand that
didn't require the "=" preceding a formula so I'm constantly running into the
problem of having to go back and insert the "=" in each formula cell. To do
this, I came up with:

Sub Equation()

With Selection
.FormulaR1C1 = "=" & .FormulaR1C1
End With

End Sub

.... which works perfectly as long as only one cell is selected. If I select
a range of cells I get the error message:

Run-time error '13':
Type mismatch

What to do?
 
T

Tim Zych

How about looping.

Dim rng As Range, cell As Range
Set rng = Selection
For Each cell In rng.Cells
cell.FormulaR1C1 = "=" & cell.Value
Next
 
R

Rick Rothstein \(MVP - VB\)

You will want to iterate through the cells in the Selection...

Dim R As Range
For Each R In Selection
R.FormulaR1C1 = "=" & R.FormulaR1C1
Next

Rick
 
R

Rick Rothstein \(MVP - VB\)

Sorry... I accidentally sent this post when I actually meant to cancel it.

Rick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top