How can i remove the "=" when i get a formula in excel and pull it into VBA

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,195
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone,
hoping someone can help me,
I've a small sample of a verey large macro but it should show you what i need

heres the code
VBA Code:
Sub test1()

Dim cell As Range
For Each cell In Selection
    If cell.HasFormula Then
    frml = cell.Formula
    MsgBox frml
        End If
Next

End Sub

now what i want is the same as this but instead of bringing in the formula with the "=" at the begining just remove the "="

so currently msgbox gives me say "=Sum(A1:G7)"

I just want "Sum(A1:G7)" so simple remove the "=" from the front of the value we get

please help if you can

Thanks
Tony
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Hi
Try
VBA Code:
Sub test1()
    Dim cell As Range
    For Each cell In Selection
        If cell.HasFormula Then
            frml = cell.Formula
            MsgBox Replace(frml, "=", "")
        End If
    Next
End Sub
 
Upvote 0
I'd use:

VBA Code:
frml = Mid$(cell.Formula, 2)
 
Upvote 0
Solution

Forum statistics

Threads
1,215,472
Messages
6,125,011
Members
449,204
Latest member
tungnmqn90

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