+ Reply to Thread
Results 1 to 3 of 3

Expanding Range Problem

  1. #1
    Registered User
    Join Date
    08-08-2014
    Location
    Hampshire, England
    MS-Off Ver
    2010
    Posts
    6

    Expanding Range Problem

    Hopefully this is straightforward but the solution eludes me.

    I have a single column of data (actually these are daily closing stock prices).

    I am looking to produce a second column showing the maximum value of the r2 coefficient of determination using the excel LINEST function.

    The problem is that I need to look at an expanding range of data values eg (a150:a1000), (a149:a1000), (a148:a1000), etc.

    So for each step the range expands by 1 cell.

    I can do this in excel using the "height" value in the "offset" command but this doesn't seem to exist in VBA.

    How do I handle a range which expands by 1 cell each step?

    I have tried using the "cell" property as in Range(cells(150,1),cells(1000,1)) but this doesn't help as the arguments cannot be variables.

    Hopefully I'm missing the obvious.
    Last edited by horneblower; 08-10-2014 at 06:04 AM.

  2. #2
    Registered User
    Join Date
    06-21-2013
    Location
    Wiltshire, UK
    MS-Off Ver
    365 Version 2210 Build 16.0.15726.20070
    Posts
    72

    Re: Expanding Range Problem

    Quote Originally Posted by horneblower View Post
    .... as the arguments cannot be variables.
    Are you saying you do NOT want to use variables or Cells() can not be used with variables?

    Cells() can be used with variables and that is how i would do the task you are describing via a loop.

    You can also do this without VBA.
    • Put in your first formula using LINEST()
    • Highlight the first cell reference and make it absolute (press F4)
    • You should have something like LINEST($J$10:J13,K10:K13,,FALSE)
    • Now when you copy down the formula, the first cell reference is fixed but the end cell of the range expands
    Isskint, i get satisfaction out of helping others

  3. #3
    Registered User
    Join Date
    08-08-2014
    Location
    Hampshire, England
    MS-Off Ver
    2010
    Posts
    6

    Re: Expanding Range Problem

    isskint,

    Thanks for your reply.

    I can, and want to, use a variable to step through from say (a150:a160) to (a150:a1500).

    I tried using cells but kept getting an error message saying I can't do that. Perhaps I got the syntax wrong. I'll try again.

    I have done it in excel in the manor you describe. It's just that each cell looks for the max of about 1,000 linest calculations and there are about 5,000 cells to do this on...and about 200 different stocks to do THAT on so we're talking about a lot of calculations. I was hoping to automate it a bit.

    Thanks again

    horneblower
    Last edited by horneblower; 08-10-2014 at 06:28 AM.

  4. #4
    Registered User
    Join Date
    08-08-2014
    Location
    Hampshire, England
    MS-Off Ver
    2010
    Posts
    6

    Re: Expanding Range Problem

    isskint,

    I just tried again with cells().
    It works.
    Many thanks.

    horneblower

  5. #5
    Registered User
    Join Date
    08-08-2014
    Location
    Hampshire, England
    MS-Off Ver
    2010
    Posts
    6

    Re: Expanding Range Problem

    isskint,

    I just tried again with cells().
    It works.
    Many thanks.

    horneblower

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Expanding the selection range
    By Priyanka_85 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-23-2013, 05:47 PM
  2. For each cell in range loop does not recognize expanding range
    By jhren in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-07-2013, 07:49 AM
  3. Conditional formatting problem with 'applies to' when expanding a range
    By gtol in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-29-2013, 07:18 PM
  4. How to adress an expanding range
    By Kim1974 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-02-2010, 10:03 AM
  5. Auto expanding Range
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-30-2005, 03:05 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1