Excel VBA Check if Cell has particular Formula (VBA)

Posted on 2015-01-08
Medium Priority
Last Modified: 2015-01-08

I'm trying to check if cells have a particular function (subtotal).    I was thinking about basing it on

Function IsFormula(cell_ref As Range)
    IsFormula = cell_ref.HasFormula
End Function
from Mr. Excel but I can't seem to make it work.

Question by:mattfmiller
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 34

Accepted Solution

Norie earned 2000 total points
ID: 40539008
Function IsSubTotalFormula(cell_ref As Range) As Boolean
    If cell_ref.HasFormula Then
        IsSubTotalFormula = InStr(cell_ref.Formula, "SUBTOTAL") > 0
    End If
End Function

Open in new window


Author Closing Comment

ID: 40539016
Thank you very much.  It was killing me.
LVL 23

Expert Comment

by:Michael Fowler
ID: 40539017
This will do the trick

Function IsSubTotal(cell_ref As Range)
    If InStr(cell_ref.Formula, "SUBTOTAL") = 0 Then
        IsSubTotal = False
        IsSubTotal = True
    End If
End Function

Open in new window

LVL 23

Expert Comment

by:Michael Fowler
ID: 40539020
way too slow, closed before I posted

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question