Convert formula string to text

dmcgoo

New Member
Joined
Dec 1, 2003
Messages
46
Hi all

I am trying to convert the following cell formula into a text string so that I can use the "mid" formula to pick up some of the text.

='[20031102.xls]Day Perf Report'!$D$6

I have not had any luck in being able to do this :oops: - can anybody help?

Thanks muchly.
 
Well, you can use the MidFun() that you declare in a module in vba

Code:
Function MidFun(rg As Range, iStart As Integer, iNum As Integer) As String

Application.Volatile
MidFun = Mid(rg.Formula, iStart, iNum)

End Function

and use it:
B1= MIDFUN(A1,1,2)

just as the Mid function...

But I think there is surely a way without using a personnalised function in vba...
 
Upvote 0

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Hi, I gave up on trying to do this all as a formula so theres a formula & macro combo solution.

Place these into your module...

Code:
Function ShowF(Rng As Range)
ShowF = Rng.Formula
End Function

Sub Convert2Formula()
Dim Rng As Range, c
Set Rng = Application.InputBox(prompt:="Select range to convert", _
Title:="Convert string to formula", Type:=8)

For Each c In Rng
c.Formula = c.Value
Next c

End Sub

Now use the ShowF formula with mid to determine the final string you need.
eg

A1 formula is =Sheet1!A1
to turn this into just A1 do this...
="=" & Mid(ShowF(A1),9,2)

Once you have all the formulas as you would like then run the Convert2Formula macro which changes this from a string into a formula. Note that the equal sign must be in the string but could be amended to auto include this if you want.

hth
 
Upvote 0
Thanks for your help guys! I will try these out and let you know if I have any more problems!

Cheers (y)

DM
 
Upvote 0
Hi there

I have found a work around - Copy your formulas to a column next to the current formula. Then you highlight the new column and Find and replace the = with '
Your new column will then have the formula in text. Make your changes and then just Find and replace the ' with =

Hope this helps you.
 
Upvote 0

Forum statistics

Threads
1,217,981
Messages
6,139,761
Members
450,230
Latest member
RStasicky

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