Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default Using a variable in a formula

I have defined this range:

Range("A1").Select
Range(Selection, Selection.End(xlDown)).Select
Dim Population As Range
Set Population = Selection

And then I want to use this range in the percentile function, but I haven't
been able to figure it out:

Range("B1").Select
ActiveCell.Formula = "=PERCENTILE(MarketValues,0.2)"

Any help would be greatly appreciated. Thanks.
Noah
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Using a variable in a formula


Hello Noah,

This should work for you...


Dim marketvalues As Range

marketvalues = Range("A1:A" & Rows.Count).End(xlUp)

Range("B2").Formula = "=PERCENTILE(MarketValues,0.2)"


Sincerely,
Leith Ros

--
Leith Ros
-----------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...fo&userid=1846
View this thread: http://www.excelforum.com/showthread.php?threadid=48000

  #3   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default Using a variable in a formula

Where are you defining "MarketValues"?

Is MarketValues a named range that is the same as population? If so, this
seemed to work for me:

Sub test()
Dim Population As Range
Set Population = Range("A1", Range("A1").End(xlDown))

Application.Names.Add Name:="Marketvalues", _
RefersTo:=Population

Range("B1").Formula = "=PERCENTILE(MarketValues,0.2)"

End Sub


"Noah" wrote:

I have defined this range:

Range("A1").Select
Range(Selection, Selection.End(xlDown)).Select
Dim Population As Range
Set Population = Selection

And then I want to use this range in the percentile function, but I haven't
been able to figure it out:

Range("B1").Select
ActiveCell.Formula = "=PERCENTILE(MarketValues,0.2)"

Any help would be greatly appreciated. Thanks.
Noah

  #4   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default Using a variable in a formula

I couldn't get it to work w/o some changes. You need a set statement for
marketvalues. For me, the Range statement only returned cell A1. In the
Percentile function, you have to refer to the marketvalues.address as Excel
won't recognize marketvalues (you'll get a NAME error).

Dim marketvalues As Range
Set marketvalues = Range("A1", Range("A" & Rows.Count).End(xlUp))
Range("B2").Formula = "=PERCENTILE(" & marketvalues.Address & ",0.2)"




"Leith Ross" wrote:


Hello Noah,

This should work for you...


Dim marketvalues As Range

marketvalues = Range("A1:A" & Rows.Count).End(xlUp)

Range("B2").Formula = "=PERCENTILE(MarketValues,0.2)"


Sincerely,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465
View this thread: http://www.excelforum.com/showthread...hreadid=480006


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
Variable within a formula Tom Melosi Excel Worksheet Functions 4 August 21st 07 04:07 AM
Using a variable in formula DtTall Excel Programming 2 August 15th 05 04:23 PM
Using a second variable within a formula... Ed Anton Excel Discussion (Misc queries) 2 February 18th 05 11:51 AM
Variable in a formula GM[_2_] Excel Programming 6 March 3rd 04 06:27 PM
Variable to formula. russell \(skmr3\) Excel Programming 1 July 30th 03 07:11 AM


All times are GMT +1. The time now is 05:14 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"