Macro - Insert Equal Sign to Convert String to Formula

  • Thread starter Thread starter Access''03_NewUser
  • Start date Start date
Sorry, I think I hit the post button on accident? Allow me to expand on my
own previous post...

I am attempting to write a macro to insert a prefix to each cell in a column
of string values. The prefix will be an equal sign; My intent is that the
string values will execute as formulas once the macro has been executed.

Any guidance/assistance is greatly appreciated.
 
Option Explicit
Sub testme01()

Dim myRng As Range
Dim myCell As Range

Set myRng = Nothing

On Error Resume Next
With Worksheets("Somesheetnamehere")
Set myRng = .Range("B2", .Cells(.Rows.Count, "B").End(xlUp)) _
.SpecialCells(xlCellTypeConstants)
End With
On Error GoTo 0

If myRng Is Nothing Then
MsgBox "No constants!"
Exit Sub
End If

For Each myCell In myRng.Cells
With myCell
.NumberFormat = "General"
.Formula = "=" & .Value
End With
Next myCell

End Sub
 

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

Back
Top