Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,574
Default getformula UDF

I have the following code as a UDF which allows you to display the formula
for a referenced cell:

Function GetFormula(Cell As Range) As String
GetFormula = Cell.Formula
End Function

So, if A1 has as its formula =2+3, and I enter into B1 =getformula(A1), =2+3
is shown.

All well and good.

However, I have a number of cells formatted as times (8:30AM, etc.) and,
when I use =getformula(cell) on them, strange numbers return: .354166666...

Ideas? Does this have to do with 8:30AM being 35.4% of a complete day?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,574
Default getformula UDF

Actually, for anyone's reference, my supposition below is true, as when I
changed the time to 12:00 PM the returned value was .5 and 12 hours is .5 of
24...

Weird.

Dave

"Dave F" wrote:

I have the following code as a UDF which allows you to display the formula
for a referenced cell:

Function GetFormula(Cell As Range) As String
GetFormula = Cell.Formula
End Function

So, if A1 has as its formula =2+3, and I enter into B1 =getformula(A1), =2+3
is shown.

All well and good.

However, I have a number of cells formatted as times (8:30AM, etc.) and,
when I use =getformula(cell) on them, strange numbers return: .354166666...

Ideas? Does this have to do with 8:30AM being 35.4% of a complete day?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,089
Default getformula UDF

Yep, that sums it up. Dates and times are held as numbers relative to a
reference point. 08:30 is just over a third of the way through the day, so,
0.354...

It's not a formula, it's a value. Perhaps you need to get your function to
check for formulae ?

Regards

Trevor


"Dave F" wrote in message
...
I have the following code as a UDF which allows you to display the formula
for a referenced cell:

Function GetFormula(Cell As Range) As String
GetFormula = Cell.Formula
End Function

So, if A1 has as its formula =2+3, and I enter into B1 =getformula(A1),
=2+3
is shown.

All well and good.

However, I have a number of cells formatted as times (8:30AM, etc.) and,
when I use =getformula(cell) on them, strange numbers return:
.354166666...

Ideas? Does this have to do with 8:30AM being 35.4% of a complete day?



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default getformula UDF

Try

Function GetFormula(Cell As Range) As String
If Cell.hasFormula Then
GetFormula = Cell.Formula
Else
GetFormula = ""
End If
End Function

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Dave F" wrote in message
...
I have the following code as a UDF which allows you to display the formula
for a referenced cell:

Function GetFormula(Cell As Range) As String
GetFormula = Cell.Formula
End Function

So, if A1 has as its formula =2+3, and I enter into B1 =getformula(A1),

=2+3
is shown.

All well and good.

However, I have a number of cells formatted as times (8:30AM, etc.) and,
when I use =getformula(cell) on them, strange numbers return:

..354166666...

Ideas? Does this have to do with 8:30AM being 35.4% of a complete day?



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to use GETFORMULA() in EXCEL 2003? romelsb Excel Worksheet Functions 2 November 1st 06 09:16 AM
array formulas and getformula UDF Dave F Excel Worksheet Functions 8 August 10th 06 09:32 PM
GetFormula function- Need help showing formulas only- [email protected] Excel Worksheet Functions 2 January 9th 06 02:52 PM


All times are GMT +1. The time now is 01:31 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"