Review formula rather than value in VBA

Andy David Clarke

New Member
Joined
Jun 14, 2007
Messages
12
I'm tring to write a macro that will analyse a formula from a cell in Excel.

If the cell I'm looking at it is =SUMIF(Sheet1!A:A,A3,Sheet1!B:B), I want to analyse this formula:
if doesn't contains SUMIF then exit sub
then return variables for:
The Sheet I'm looking at (Sheet1)
The item I'm looking at (A3).

If I could get at the actual formula, I could cut it up as required:
between = & ( is the function
between ( & ! is the sheet
between , & , is the item I'm looking at

But I'm struggling to find a way to actually analyse the formula as VBA seems to want to look at the result or the formula itself rather than how it is built up. I've tried cell.formula, but can't make this work.

Any help would be much appreciated as I've never really used VBA to look at this before, so am struggling...
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Try like this

Code:
Dim fmla As String
fmla = Range("A1").Formula

This will return the formula including the initial =
 
Upvote 0
Thanks - As I mentioned, I was trying cell.formula but couldn't get it to work so started trying more complicated stuff going down blind alleys...
However, had another quick look & can use it as you suggest, with = Mid(ActiveCell.Formula, 2, 5) returning SUMIF.
Thanks again
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,730
Members
452,939
Latest member
WCrawford

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