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


hey !!!
please help ...
1).
I have recorded a macro which calculates average of some sample.
it uses the formula "=AVERAGE(A1:AD1)" (average of 30 data)
when I run the macro next time I have only 20 data in the sample.
I want macro to calculate it as "=AVERAGE(A1:T1)"
How to make the range to be variable?

2).
I calculated the average for the first row, Then I pasted the value
for next 2000 cells.
here are the code lines ..

ActiveCell.FormulaR1C1 = "=AVERAGE(Sheet1!R[-1]C:R[-1]C[29])"
Range("A2").Select
Selection.AutoFill Destination:=Range("A2:A2001")
Type:=xlFillDefault

next time when I run the macro I have only 1000 simulations and I wan
to autofill the range as "A2:A1001".
but with the recorded macro it is autofilling till A2001.
How to put variable in this ?

Thanks in advance...
--rajendr

--
rsank
-----------------------------------------------------------------------
rsankh's Profile: http://www.msusenet.com/member.php?userid=187
View this thread: http://www.msusenet.com/t-187051322

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 121
Default variable range

I will choose to answer part two... :-), the answer to part 1 is similar.


One choice is to Dimension a range variable and you can set its value by
letting the user enter it in a inputbox.

Your code:
ActiveCell.FormulaR1C1 = "=AVERAGE(Sheet1!R[-1]C:R[-1]C[29])"
Range("A2").Select
Selection.AutoFill Destination:=Range("A2:A2001"),
Type:=xlFillDefault


can be changed to this code:

ActiveCell.FormulaR1C1 = "=AVERAGE(Sheet1!R[-1]C:R[-1]C[29])"
Range("A2").Select

Dim MyRange As Range
Set MyRange = ActiveSheet.Range("Sheet1!" & _
InputBox("Input the range in format shown:", , "A2:A1001"))
Selection.AutoFill Destination:=MyRange, _
Type:=xlFillDefault



"rsankh" wrote in message
...

hey !!!
please help ...
1).
I have recorded a macro which calculates average of some sample.
it uses the formula "=AVERAGE(A1:AD1)" (average of 30 data)
when I run the macro next time I have only 20 data in the sample.
I want macro to calculate it as "=AVERAGE(A1:T1)"
How to make the range to be variable?

2).
I calculated the average for the first row, Then I pasted the values
for next 2000 cells.
here are the code lines ..

ActiveCell.FormulaR1C1 = "=AVERAGE(Sheet1!R[-1]C:R[-1]C[29])"
Range("A2").Select
Selection.AutoFill Destination:=Range("A2:A2001"),
Type:=xlFillDefault

next time when I run the macro I have only 1000 simulations and I want
to autofill the range as "A2:A1001".
but with the recorded macro it is autofilling till A2001.
How to put variable in this ?

Thanks in advance...
--rajendra


--
rsankh
------------------------------------------------------------------------
rsankh's Profile: http://www.msusenet.com/member.php?userid=1879
View this thread: http://www.msusenet.com/t-1870513229



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default variable range

rajendra,

1. The Average function ignores text, logical values and empty cells,
so if you clear the row each time, you won't need a dynamic range.

2. Use a variable that contains the number of simulations...
Dim lngSims as Long
lngSims = 1001
....
Selection.AutoFill Destination:=Range("A2",Cells(lngSims,1))

Jim Cone
San Francisco, USA


"rsankh" wrote in message
...

hey !!!
please help ...
1).
I have recorded a macro which calculates average of some sample.
it uses the formula "=AVERAGE(A1:AD1)" (average of 30 data)
when I run the macro next time I have only 20 data in the sample.
I want macro to calculate it as "=AVERAGE(A1:T1)"
How to make the range to be variable?

2).
I calculated the average for the first row, Then I pasted the values
for next 2000 cells.
here are the code lines ..

ActiveCell.FormulaR1C1 = "=AVERAGE(Sheet1!R[-1]C:R[-1]C[29])"
Range("A2").Select
Selection.AutoFill Destination:=Range("A2:A2001"),
Type:=xlFillDefault

next time when I run the macro I have only 1000 simulations and I want
to autofill the range as "A2:A1001".
but with the recorded macro it is autofilling till A2001.
How to put variable in this ?

Thanks in advance...
--rajendra

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
Use Sum() with variable range Jeff Excel Worksheet Functions 4 April 7th 09 05:26 AM
setting a range variable equal to the value of a string variable Pilgrim Excel Programming 2 July 1st 04 11:32 PM
Using Variable in RANGE Jim[_31_] Excel Programming 2 April 26th 04 01:18 PM
variable range: l just can't get there! ste mac Excel Programming 2 October 27th 03 06:43 PM
Problem trying to us a range variable as an array variable TBA[_2_] Excel Programming 4 September 27th 03 02:56 PM


All times are GMT +1. The time now is 11:12 AM.

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

About Us

"It's about Microsoft Excel"