+ Reply to Thread
Results 1 to 5 of 5

Trouble with RSq function in VBA

  1. #1
    Registered User
    Join Date
    04-16-2008
    Posts
    3

    Trouble with RSq function in VBA

    First let me describe what I'm TRYING to do. I have a large dataset of test results that is Autofiltered to sort by 20 or so different columns. I also have a number of charts that conveniently show only the test results that are visible in the Autofilter. I guess this is the default behavior of charts?

    I am trying to put together a summary of performance predictors that are compared to each other by their linear regression R-squared value. The RSq function does this just fine, but it does not ignore the hidden rows when Autofiltered. So I'm writing some code to do this using the "SpecialCells(xlCellTypeVisible)" method and running into problems.

    When I create ranges like this:

    Please Login or Register  to view this content.
    It works fine with the excel function Sum, and sums only the visible filtered cells. When I use this same format on 2 ranges with RSq, I get a 1004 error. When I use the range above without the SpecialCells property, RSq works just fine. Why doesn't RSq like using the SpecialCells property? I need help finding a work-around.

    One thought I had that probably isn't possible - can VBA read the R-squared value off of a chart with a best fit curve on it? Since my charts only show the filtered data this would give me what I want.
    Last edited by puckalicious; 04-17-2008 at 03:08 PM.

  2. #2
    Registered User
    Join Date
    04-16-2008
    Posts
    3
    Ok, so I'm scrapping that approach and trying to manually calculate R squared by using For/Next loop that tests each row to see if it is visible or hidden with the Autofilter.

    I'm running into an issue with setting up a range variable. What am I doing wrong?

    Please Login or Register  to view this content.
    This gives a 1004 error.
    Last edited by puckalicious; 04-17-2008 at 03:08 PM.

  3. #3
    Registered User
    Join Date
    04-16-2008
    Posts
    3
    ok sorry for not reading forum rules before posting. edited my posts.

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    Maybe capture the visible cell values in a pair of Variants, and then compute Rsq from those:

    Please Login or Register  to view this content.

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello puckalicious,

    SHG's idea is a good one. The arrays will be faster and will overcome an inherent problem wih using "visible cells". The cells returned by "visible cells" are dependent on your filter and most likely are not going to contiguous. The cells used in RSQ must be contiguous, or it will throw an error. All the values in the arrays will be contiguous and not cause a problem.

    Sincerely,
    Leith Ross

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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