Convert several lines of string text (think range names) to actual formulas using a macro

mwf05

New Member
Joined
Jun 19, 2006
Messages
10
I am trying to determine how to edit several rows existing string text into a live formula. For instance STEPS_TO_FRONT_DOOR * GUESTS_PER_DAY, STEPS_TO_BACK_DOOR * DOG_BREAKS, etc. When I run the macro to convert the string text to a formula F2, Ctrl+Home, = Enter is saves the string text that was in the cell with the result. I just want it to edit the cell and convert it to an actual formula by putting an "=" at the beginning and then I want it to go to the next row with string text and convert it to a formula. Unfortunately, it just replicates the first formula edit when the macro was recorded.
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Not sure what you're saying. If you successfully convert the string to a formula, what you'll see is the formula result and not the formula text. If you want to see the formula as a string, start that string with a single quote. If that doesn't help, post what you're trying to convert and what you're trying to convert it to.
 
Upvote 0
The macro below

VBA Code:
Sub ConvCell()
    Dim myCell As Range, strRng As String

    For Each myCell In Range("A2:A" & Range("A" & Rows.Count).End(xlUp).Row)
        strRng = myCell.Value
        myCell.Formula = "=" & strRng
    Next

End Sub

converts

Book1
ABCDEFG
2Back*Dog6
3Front*Guests3
4Guests*Dog2
5Front*Dog5
Sheet1


to

Book1
ABCDEFG
2106
3183
4152
5305
Sheet1
Cell Formulas
RangeFormula
A2A2=Back*Dog
A3A3=Front*Guests
A4A4=Guests*Dog
A5A5=Front*Dog
Named Ranges
NameRefers ToCells
Back=Sheet1!$G$4A2
Dog=Sheet1!$G$5A2, A4:A5
Front=Sheet1!$G$2A5, A3
Guests=Sheet1!$G$3A3:A4
 
Upvote 0
MARK858,
Thank you, your process works, but not for the scenario I have. My cells (while in the same column) that I want to convert aren't all together. They are several rows apart which varies. The macro I tried by recording my steps is:
Sub Macro4()
'
' Macro4 Macro
'

'
Selection.End(xlDown).Select
ActiveCell.FormulaR1C1 = "= SQ_FT_COOLER_FLOOR"
ActiveCell.Offset(1, 0).Range("A1").Select
End Sub

When the above is repeated for each cell with a formula that needs to be converted, each cell has the same formula of = SQ_FT_COOLER_FLOOR.

Your process worked, but all the rows that had nothing were also converted into formula cells.
 
Upvote 0
VBA Code:
Sub ConvCell()
    Dim myCell As Range, strRng As String

    For Each myCell In Range("A2:A" & Range("A" & Rows.Count).End(xlUp).Row)
        If myCell <> "" Then
            strRng = myCell.Value
            myCell.Formula = "=" & strRng
        End If
    Next

End Sub
 
Upvote 0
Solution
VBA Code:
Sub ConvCell()
    Dim myCell As Range, strRng As String

    For Each myCell In Range("A2:A" & Range("A" & Rows.Count).End(xlUp).Row)
        If myCell <> "" Then
            strRng = myCell.Value
            myCell.Formula = "=" & strRng
        End If
    Next

End Sub
Works perfectly! Thank you very much.
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,191
Members
452,616
Latest member
intern444

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top