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

I am working on a spreadsheet with a variable number of columns. It is
a financial projection spreadsheet (retirement planning) of high
complexity.

With 100 columns (i.e. a 100 year projection), the spreadsheet is both
huge and slow. I don't think I always want only 100 columns though.

I'm trying to create a version which starts with a more manageable
number of years, i.e. 5, which can then be extended with a macro. This
way I would have a file of only a few hundred k to distribute, which
would run quickly, and if someone wants to create a 10 megabyte 100
column monster out of it, its their choice.

If I want to drag the range F8:F12 right ten columns, I would use this
code:

Range("$F$8:$F$12").Select
Selection.AutoFill Destination:=Range("F8:O12"), Type:=xlFillDefault

Easy enough. A recorded macro does that.

But I want to drag by a variable number of columns.

If I want to project for 10 years, I would have a cell with the number
10 in it and a button next to it saying "Go" or something.

My number of years to project is in a cell specified by
Range("projectionyears").Value

And I don't actually want to specify my range to extend from as
Range("$F$8:$F$12"), the range was actually called
Range("startingcolumn").

So what I want to know, is how to take the range
Range("startingcolumn") and extend this right by
Range("projectionyears").Value columns.

Travis

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default Dragging a range of cells

try using something like

mx=range("a10")
range("f8:f12").autofill destination:=range(cells(8,"f"),cells(12,mx))

--
Don Guillett
SalesAid Software

"travis" wrote in message
ps.com...
I am working on a spreadsheet with a variable number of columns. It is
a financial projection spreadsheet (retirement planning) of high
complexity.

With 100 columns (i.e. a 100 year projection), the spreadsheet is both
huge and slow. I don't think I always want only 100 columns though.

I'm trying to create a version which starts with a more manageable
number of years, i.e. 5, which can then be extended with a macro. This
way I would have a file of only a few hundred k to distribute, which
would run quickly, and if someone wants to create a 10 megabyte 100
column monster out of it, its their choice.

If I want to drag the range F8:F12 right ten columns, I would use this
code:

Range("$F$8:$F$12").Select
Selection.AutoFill Destination:=Range("F8:O12"), Type:=xlFillDefault

Easy enough. A recorded macro does that.

But I want to drag by a variable number of columns.

If I want to project for 10 years, I would have a cell with the number
10 in it and a button next to it saying "Go" or something.

My number of years to project is in a cell specified by
Range("projectionyears").Value

And I don't actually want to specify my range to extend from as
Range("$F$8:$F$12"), the range was actually called
Range("startingcolumn").

So what I want to know, is how to take the range
Range("startingcolumn") and extend this right by
Range("projectionyears").Value columns.

Travis



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Dragging a range of cells

With Range("startingcolumn")
.AutoFill Destination:= _
.Resize( ,Range("projectionyears").Value), _
Type:=xlFillDefault
End With

--
Regards,
Tom Ogilvy


"travis" wrote:

I am working on a spreadsheet with a variable number of columns. It is
a financial projection spreadsheet (retirement planning) of high
complexity.

With 100 columns (i.e. a 100 year projection), the spreadsheet is both
huge and slow. I don't think I always want only 100 columns though.

I'm trying to create a version which starts with a more manageable
number of years, i.e. 5, which can then be extended with a macro. This
way I would have a file of only a few hundred k to distribute, which
would run quickly, and if someone wants to create a 10 megabyte 100
column monster out of it, its their choice.

If I want to drag the range F8:F12 right ten columns, I would use this
code:

Range("$F$8:$F$12").Select
Selection.AutoFill Destination:=Range("F8:O12"), Type:=xlFillDefault

Easy enough. A recorded macro does that.

But I want to drag by a variable number of columns.

If I want to project for 10 years, I would have a cell with the number
10 in it and a button next to it saying "Go" or something.

My number of years to project is in a cell specified by
Range("projectionyears").Value

And I don't actually want to specify my range to extend from as
Range("$F$8:$F$12"), the range was actually called
Range("startingcolumn").

So what I want to know, is how to take the range
Range("startingcolumn") and extend this right by
Range("projectionyears").Value columns.

Travis


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default Dragging a range of cells


Tom Ogilvy wrote:
With Range("startingcolumn")
.AutoFill Destination:= _
.Resize( ,Range("projectionyears").Value), _
Type:=xlFillDefault
End With


Thanks Tom, that's a very elegant solution.

Travis

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
Dragging values down a range using a colum to determine its length AlexJarvis Excel Worksheet Functions 4 April 29th 10 04:15 PM
How to maintain a set range of cells when dragging a formula (e.gmonthlyannual data) Justinalexander Excel Discussion (Misc queries) 2 February 3rd 09 12:13 PM
Dragging a range Gaurav[_2_] Excel Worksheet Functions 2 November 29th 07 12:47 AM
Excel range selection as if dragging, keyboard not responding lohende New Users to Excel 1 July 22nd 07 03:26 PM
Dragging range (array) Rita Palazzi Excel Discussion (Misc queries) 1 June 29th 06 06:19 PM


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