Excel VBA Check if Cell has particular Formula (VBA)

Posted on 2015-01-08
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 500 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…

705 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