Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / May 2006

Tip: Looking for answers? Try searching our database.

HasFormula() vs. has a "numeric" entry

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
mark kubicki - 25 May 2006 23:04 GMT
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
Chip Pearson - 25 May 2006 23:28 GMT
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

> How can I distinguish if a cell has formula entry (ex:
> =sum(A1:A25) ) vs. a simple "numeric entry (ex: 123)?
[quoted text clipped - 4 lines]
> thanks in advance,
> -mark
witek - 26 May 2006 00:08 GMT
what about formulas which use named ranges.
like
=MyRange +1
?

> Try
>
[quoted text clipped - 17 lines]
>>thanks in advance,
>>-mark
Dana DeLouis - 26 May 2006 00:23 GMT
> 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

Signature

HTH.  :>)
Dana DeLouis
Windows XP, Office 2003

> what about formulas which use named ranges.
> like
[quoted text clipped - 21 lines]
>>>thanks in advance,
>>>-mark
Joerg - 26 May 2006 04:29 GMT
> > what about formulas which use named ranges.
>
[quoted text clipped - 9 lines]
>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
keepITcool - 26 May 2006 12:24 GMT
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.

Signature

keepITcool

| www.XLsupport.com | keepITcool chello nl | amsterdam

> > what about formulas which use named ranges.
>
[quoted text clipped - 7 lines]
>        ' There are cell references...
>    End If
Chip Pearson - 26 May 2006 15:08 GMT
Very good point.

> what about formulas which use named ranges.
> like
[quoted text clipped - 22 lines]
>>>thanks in advance,
>>>-mark
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.