+ Reply to Thread
Results 1 to 5 of 5

Adding Only Visible Cells to Array Concept

  1. #1
    Registered User
    Join Date
    05-31-2020
    Location
    Tokyo
    MS-Off Ver
    Microsoft Office 365
    Posts
    11

    Question Adding Only Visible Cells to Array Concept

    Hi Everyone,

    I was looking for a solution to add only visible cells to an array and I was able to find one that works.

    While it seems simple, I am having trouble grasping the concept of why this solution works so well.

    Please Login or Register  to view this content.
    Particulary, I want to know why setting a range for Cell 1 and the same range for Cell 2 is able to isolate the desired range.
    Why wouldn't one set the cell for cell1 to "C2" and the cell for cell2 to "C208"? I've noticed when I try to test this, the loop appears to never end...

    Also, when I print the value of ys(0), ys(etc..), it seems to be all over the place, but the value of a(0), a(etc..) is always the desired visible cells in my list.
    How does this work? What is the initial value of ys, and how does the loop end properly?

    Thank you

  2. #2
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Adding Only Visible Cells to Array Concept

    There is no cell1, cell2 in your code. Its hard for us to comment on code that we can't see.

    Note that someRange(2) is a short-hand version of someRange.Cells(2,1) and does not take filtering or visible cells into account as one increments the 2.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  3. #3
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,274

    Re: Adding Only Visible Cells to Array Concept

    Without seeing the worksheet in question nor the rest of the code...
    Please Login or Register  to view this content.
    ...assigns all visible cells in column C to xs. As to using "C2:C208" twice, it may be that there is a non-continuous break in the data between those cells and the End(xlDown) would not get all the cells in column C. If not, using
    Please Login or Register  to view this content.
    would work just as well. Also it just may be that a copy of the range was in the clipboard and it was just quicker to write the code...

  4. #4
    Registered User
    Join Date
    05-31-2020
    Location
    Tokyo
    MS-Off Ver
    Microsoft Office 365
    Posts
    11

    Re: Adding Only Visible Cells to Array Concept

    Quote Originally Posted by mikerickson View Post
    There is no cell1, cell2 in your code. Its hard for us to comment on code that we can't see.
    Apologies, I will attempt to clarify. By Cell1 and Cell2, I was meaning to refer to the syntax Range(Cell1, [Cell2]).

    Quote Originally Posted by mikerickson View Post
    Note that someRange(2) is a short-hand version of someRange.Cells(2,1) and does not take filtering or visible cells into account as one increments the 2.
    Is this why ys takes on every value from C2 to C208? How is the array only populated with the visible cells? Is it because "xs" is the filtered range and "ys" is the entire range, and the loop searches for matches?

    When I comment out the line below and replace it with the similar uncommented line, the code executes and the loop seems to never end. The array still is accurately populated with the 5 visible values as per the filter, but the values of xs(0,1,2, etc) begin with one before the filtered value and continue to the end of the list. I don't understand how the change causes the loop to continue, or how ys, a range that hasn't been initiated, is able to pass the filtered values to the array accurately.
    Please Login or Register  to view this content.
    Thank you

  5. #5
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Adding Only Visible Cells to Array Concept

    This code:

    Please Login or Register  to view this content.
    isolates the ys at large from the xs in particular - so that your a values can only be the particular xs values.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

+ 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. [SOLVED] Google sheets: Conditional formatting (same concept, different cells)
    By rayted in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 1
    Last Post: 08-03-2018, 10:40 AM
  2. Replies: 1
    Last Post: 01-23-2015, 12:36 PM
  3. Fill Array with data in visible cells in column
    By jeroenv in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-22-2014, 08:30 AM
  4. [SOLVED] Problems to store visible cells into array
    By cgkmal in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 08-11-2014, 08:21 PM
  5. [SOLVED] Adding a Row Wise Formula in Filtered Special Visible cells only
    By e4excel in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-01-2013, 09:46 AM
  6. Creating array of specialcells(visible) returns only first x cells
    By Bishonen in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-27-2013, 11:04 AM
  7. Copy Visible cells and paste values only to visible target cells
    By wotadude in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-28-2010, 04:09 AM

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