PC Review


Reply
Thread Tools Rate Thread

Compute Named Formulas

 
 
JeremyJ
Guest
Posts: n/a
 
      12th Jan 2009
Is there a way to grab the "Computed Value" or "Result" of a Named Formula
with in a Worksheet with VBA?

WorkSheet Name
Min=((HOUR(Time_End)*60+MINUTE(Time_End))-(HOUR(Time_Start)*60+MINUTE(Time_Start)))-Time_Break

Sub Grab_Minute()
Dim n As Name
Dim Computed_Value As Long
i = 1
For Each n In Names
If n.name = "Min" then
Computed_Value = *Compute*(n)
End if
Next n
End Sub
 
Reply With Quote
 
 
 
 
Gary''s Student
Guest
Posts: n/a
 
      12th Jan 2009
Interesting - I have never seen this question before.

Say the B10 contains 10 and B11 contains 11.
Say we have a Defined Name - alpha which is:

=Sheet1!$B$10+Sheet1!$B$11

so in the worksheet if we enter =alpha in some cell, we see 21

In VBA:

Sub servient()
For Each n In ActiveWorkbook.Names
MsgBox (Evaluate(n.Name))
Next
End Sub

will output the 21 in the msgbox
--
Gary''s Student - gsnu200826


"JeremyJ" wrote:

> Is there a way to grab the "Computed Value" or "Result" of a Named Formula
> with in a Worksheet with VBA?
>
> WorkSheet Name:
> Min=((HOUR(Time_End)*60+MINUTE(Time_End))-(HOUR(Time_Start)*60+MINUTE(Time_Start)))-Time_Break
>
> Sub Grab_Minute()
> Dim n As Name
> Dim Computed_Value As Long
> i = 1
> For Each n In Names
> If n.name = "Min" then
> Computed_Value = *Compute*(n)
> End if
> Next n
> End Sub

 
Reply With Quote
 
Bernard Liengme
Guest
Posts: n/a
 
      12th Jan 2009
Here is a very unsophisticated workaround while you (actually, while we)
await a better answer

Sub tryme()
Range("D1") = "=Myform"
myvariable = Range("D1")
Range("D1").Delete
MsgBox myvariable
End Sub

I defined Myform as =Sheet1!$A$1+Sheet1!$A$2
And the sub displayed a message box with the correct value

I experimented with getting a single member of a collection as in
Names("Myform") but this return the formula not the computed value
best wishes
--
Bernard V Liengme
Microsoft Excel MVP
http://people.stfx.ca/bliengme
remove caps from email

"JeremyJ" <(E-Mail Removed)> wrote in message
news:2AD80316-7FC5-4E6B-BF11-(E-Mail Removed)...
> Is there a way to grab the "Computed Value" or "Result" of a Named Formula
> with in a Worksheet with VBA?
>
> WorkSheet Name:
> Min=((HOUR(Time_End)*60+MINUTE(Time_End))-(HOUR(Time_Start)*60+MINUTE(Time_Start)))-Time_Break
>
> Sub Grab_Minute()
> Dim n As Name
> Dim Computed_Value As Long
> i = 1
> For Each n In Names
> If n.name = "Min" then
> Computed_Value = *Compute*(n)
> End if
> Next n
> End Sub



 
Reply With Quote
 
JeremyJ
Guest
Posts: n/a
 
      12th Jan 2009
Perfect! Thank you. The "Evaluate" function even got rid of the Equals sign
and quotes for all of the other names as well which did not have formulas. I
was removing those "manually". This works much better.

"Gary''s Student" wrote:

> Interesting - I have never seen this question before.
>
> Say the B10 contains 10 and B11 contains 11.
> Say we have a Defined Name - alpha which is:
>
> =Sheet1!$B$10+Sheet1!$B$11
>
> so in the worksheet if we enter =alpha in some cell, we see 21
>
> In VBA:
>
> Sub servient()
> For Each n In ActiveWorkbook.Names
> MsgBox (Evaluate(n.Name))
> Next
> End Sub
>
> will output the 21 in the msgbox
> --
> Gary''s Student - gsnu200826
>
>
> "JeremyJ" wrote:
>
> > Is there a way to grab the "Computed Value" or "Result" of a Named Formula
> > with in a Worksheet with VBA?
> >
> > WorkSheet Name:
> > Min=((HOUR(Time_End)*60+MINUTE(Time_End))-(HOUR(Time_Start)*60+MINUTE(Time_Start)))-Time_Break
> >
> > Sub Grab_Minute()
> > Dim n As Name
> > Dim Computed_Value As Long
> > i = 1
> > For Each n In Names
> > If n.name = "Min" then
> > Computed_Value = *Compute*(n)
> > End if
> > Next n
> > End Sub

 
Reply With Quote
 
Dana DeLouis
Guest
Posts: n/a
 
      13th Jan 2009
> If n.name = "Min" then
> Computed_Value = *Compute*(n)


Hi. I see you have a solution. Just to add...if you have a specific
name in mind, here is my preference:

Sub Demo()
Dim MyMin

'// If you have this formula...
ActiveWorkbook.Names.Add "Min", _

"=((HOUR(Time_End)*60+MINUTE(Time_End))-(HOUR(Time_Start)*60+MINUTE(Time_Start)))-Time_Break"

'// Then later in your code...
MyMin = [Min]
End Sub


Another interesting variation to Gary's solution in some situations is
to use Relative Addressing (no $ in address)
Where this points to depends on where the active cell is when this named
formula was added.

=Sheet1!B10+Sheet1!B11

The answer to this evaluation depends on where the active cell is in the
same relationship as when the named formula was generated.

Sometimes, that can be really cool...
- - -
HTH :>)
Dana DeLouis


JeremyJ wrote:
> Is there a way to grab the "Computed Value" or "Result" of a Named Formula
> with in a Worksheet with VBA?
>
> WorkSheet Name:
> Min=((HOUR(Time_End)*60+MINUTE(Time_End))-(HOUR(Time_Start)*60+MINUTE(Time_Start)))-Time_Break
>
> Sub Grab_Minute()
> Dim n As Name
> Dim Computed_Value As Long
> i = 1
> For Each n In Names
> If n.name = "Min" then
> Computed_Value = *Compute*(n)
> End if
> Next n
> End Sub

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
EXCEL07 CELL FORMULAS WILL NOT COMPUTE TO A VALUE Bearski Microsoft Excel Worksheet Functions 2 3rd Jan 2010 12:42 AM
Named ranges and pasting formulas with named references Dude3966 Microsoft Excel Programming 2 8th Oct 2008 04:15 PM
Formulas cut and paste but do not compute =?Utf-8?B?Q2hyaXM=?= Microsoft Excel Worksheet Functions 3 30th Jan 2007 11:27 PM
formulas will not compute =?Utf-8?B?cGhpbA==?= Microsoft Excel Worksheet Functions 2 20th Nov 2006 02:08 PM
Formulas that don't compute =?Utf-8?B?UGF1bHltb24=?= Microsoft Excel Worksheet Functions 3 31st Jan 2006 02:10 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:37 PM.