+ Reply to Thread
Results 1 to 7 of 7

SpecialCells(xlCellTypeVisible) Not Returning Visible Cells Resulting from AutoFilter

  1. #1
    Registered User
    Join Date
    09-07-2011
    Location
    Sacramento
    MS-Off Ver
    Excel 2007
    Posts
    37

    SpecialCells(xlCellTypeVisible) Not Returning Visible Cells Resulting from AutoFilter

    The data range on my sheet is 8 cols by 40403 rows. The first row is a header row, I have enabled AutoFilter, and selected a filter value for column 2. This filter shows approximately 180 rows (hiding the rest).

    I need VBA code that will create a range that includes the visible values from column 1 - preferably minus the header cell.

    I have tried using the SpecialCells method, but do not get the results I expect. One non-working example is:

    Please Login or Register  to view this content.
    Where do I go wrong?

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: SpecialCells(xlCellTypeVisible) Not Returning Visible Cells Resulting from AutoFilter

    Try
    Please Login or Register  to view this content.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    09-07-2011
    Location
    Sacramento
    MS-Off Ver
    Excel 2007
    Posts
    37

    Re: SpecialCells(xlCellTypeVisible) Not Returning Visible Cells Resulting from AutoFilter

    Thanks Richard, but this did not work for me. I end up with myRange (rows 1 to 179) containing the correct visible data. But then starting at row 180, myRange continues to contain the remaining non-visible rows. I am not sure if my dataset is causing the issues. I have uploaded my data. Thanks

    Zips.xlsm

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: SpecialCells(xlCellTypeVisible) Not Returning Visible Cells Resulting from AutoFilter

    That's not what I see.

    When I use the Immediate window with

    Print myrange.address
    I get


    $A$11:$A$15,$A$19,$A$23,$A$25:$A$26,$A$28:$A$29,$A$32,$A$39:$A$40,$A$43,$A$49:$A$50,$A$52:$A$55,$A$57,$A$59:$A$60,$A$66:$A$69,$A$72:$A$74,$A$76,$A$84:$A$85,$A$87,$A$89,$A$91:$A$96,$A$99,$A$101:$A$102,$A$104:$A$105,$A$107:$A$108,$A$111:$A$114,$A$116:$A$189

    Is this not what you want?

  5. #5
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,434

    Re: SpecialCells(xlCellTypeVisible) Not Returning Visible Cells Resulting from AutoFilter

    I see the same information as Richard for the returned range. The returned range contains 127 cells in 25 areas.
    Your code would only cause an error if the reference was off the sheet.

    Consider this, which returns $A$180.
    Please Login or Register  to view this content.
    But the way you think it should error as A1 only has 1 item and referencing 180 would be out of range. That assumption is incorrect.

    This on the other hand would error because it references beyond the last row on the sheet.
    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  6. #6
    Registered User
    Join Date
    09-07-2011
    Location
    Sacramento
    MS-Off Ver
    Excel 2007
    Posts
    37

    Re: SpecialCells(xlCellTypeVisible) Not Returning Visible Cells Resulting from AutoFilter

    Very helpful. I think I see what I am doing wrong. To help me better understand, what lines of code would produce the values of the first cell in myRange, and the last cell in myRange (values, not addresses)

    What would the code look like that would load the values of the visible cells (myRange) into a dynamic array?

    Thanks again...
    Last edited by Filibuster; 07-28-2012 at 12:38 PM.

  7. #7
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,434

    Re: SpecialCells(xlCellTypeVisible) Not Returning Visible Cells Resulting from AutoFilter

    Please Login or Register  to view this content.

+ 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