Determine cel contains formula '=sum()'

pvr928

Well-known Member
Joined
Oct 21, 2002
Messages
790
Hi

I'm trying to test if a cell contains '=Sum()' (the cells in question will only contain this formula, another formula or a hard coded value.

I am using this UDF:

Function IsFormula(cellref)
IsFormula = Left(Range(cellref).Formula, 4) = "=SUM"
End Function

I am getting a 'Run time error 1004' 'Method range of object _global' failed on the 'IsFormula = ... ' line in the UDF

I am referencing this UDF in another Module using:

Set rCellRef = Outputws.Cells(StartCellRow + r - 1, StartCellCol)

If IsFormula(rCellRef) = False Then ...

All of the other references are working and the code is compiling properly up until it hits the UDF.

Any thoughts on what might be causing this?

Cheers

pvr928
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
As rCellRef is

Set rCellRef = Outputws.Cells(StartCellRow + r - 1, StartCellCol)


it seems that the code is passing a range object to the function, not a string in
If IsFormula(rCellRef) = False Then


So, see if this works

Code:
[COLOR=#333333]Function IsFormula(cellref)[/COLOR]
[COLOR=#333333]      IsFormula = Left([/COLOR][COLOR=#0000ff]cellref.Formula[/COLOR][COLOR=#333333], 4) = "=SUM"[/COLOR]
[COLOR=#333333]End Function
[/COLOR]

It worked for me

Hope this helps

M.
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,199
Members
449,072
Latest member
DW Draft

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