HasFormula() vs. has a "numeric" entry

  • Thread starter Thread starter mark kubicki
  • Start date Start date
M

mark kubicki

How can I distinguish if a cell has formula entry (ex: =sum(A1:A25) ) vs. a
simple "numeric entry (ex: 123)?

-would the most efficient way be to check if Right(AnyString, 1) = "="

thanks in advance,
-mark
 
Try

Dim F As String
Dim S As String

F = ActiveCell.Formula
S = Application.ConvertFormula(F, xlA1, xlR1C1)
If F = S Then
Debug.Print "No cell references"
Else
Debug.Print "cell references"
End If
 
what about formulas which use named ranges.

Maybe one could include something like this:

Dim nPrecedents As Long

On Error Resume Next 'In case there are none
nPrecedents = ActiveCell.Precedents.Count
If n > 0 Then
' There are cell references...
End If
 
Dana DeLouis said:
Maybe one could include something like this:

Dim nPrecedents As Long

On Error Resume Next 'In case there are none
nPrecedents = ActiveCell.Precedents.Count
If n > 0 Then
' There are cell references...
End If --
HTH. :>)
Dana DeLouis


Maybe I missed something, but why not::

if ActiveCell.HasFormula then
'has formula with or without cell references (example for 'without
reference': =10+5)
else
'no formula
end if


Joerg
 
Dana,

precedents EXCLUDE references to cells other than activesheet.

[sheet1!a1].formula = "=sheet2!a1"
msgbox [sheet1!a1].precedents.count '<No CellsFound>

Testing .Formula <> .Value appears similar to .HasFormula
surprisingly it is 3x faster.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top