+ Reply to Thread
Results 1 to 7 of 7

Selecting columns using offset when there are hidden rows.

  1. #1
    Registered User
    Join Date
    11-23-2017
    Location
    Houston, TX
    MS-Off Ver
    2016 Pro
    Posts
    5

    Selecting columns using offset when there are hidden rows.

    Using Excel 2016 365 ProPlus. Table with over 100,000 rows which contains approximately 2000 duplicates. Trying to delete duplicates based on information that is not in the column that indicates the duplicates. Have tried cycling through the table using "For Each C in Range ("U2:U" & lastrow).SpecialCells(xlCellTypeVisible) and then using Offset to obtain the required selection crieteria that is in other columns (could be in either of the two duplicated rows). Offset seems to be able to offset rows but not columns. Also do not understand the interaction between ActiveCell and Offset in this situation (hidden rows).

    Not an experienced programmer.

    Thanks in advance,

    jarummel

  2. #2
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,885

    Re: Selecting columns using offset when there are hidden rows.

    Upload sample workbook that clearly demonstrate your issue with sanitized data. With manually created desired/expected output.

    There are several approach you can take with this since you have Pro Plus. Depending on how you are going to use cleaned data.

    1. PowerQuery/Get & Transform -> Load to data model or load back to sheet
    2. VBA - Advanced Filter Copy
    3. VBA - Custom code using ListObject/Array or other methods

    Offset is able to offset columns or rows. OFFSET(0,1)/OFFSET(,1) will offset by one column. First argument is for row and second is for column.
    If you don't use second argument, it will default to row (OFFSET(1)).
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

  3. #3
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Selecting columns using offset when there are hidden rows.

    Which other columns are you trying to refer to?
    If posting code please use code tags, see here.

  4. #4
    Registered User
    Join Date
    11-23-2017
    Location
    Houston, TX
    MS-Off Ver
    2016 Pro
    Posts
    5

    Re: Selecting columns using offset when there are hidden rows.

    Thanks for the quick response. I've used offset successfully for several problems but have not tried when working with hidden rows. I started by using conditional formatting to indicate the duplicate rows (always just two). I then sorted the table to get the duplicates in adjacent rows. I then filtered by color to separate the duplicates from the other table data. Interesting note is that I could not get this to work until I found a very subtle Excel limitation that color sorting will not work if the first color row is beyond 10000 rows. The data I need to determine which of the two rows to delete is in a column that does not include the duplicate values. I now have the duplicates separated from the non-duplicated rows and in logical row order. It appears that offset is offsetting to the hidden rows instead of just the non-hidden rows.


    The following snippet of code is where I'm experiencing the issue

    For Each C in Range("U2:U" & lastrow).SpecialCells(xlCellTypeVisible) ' The Next does move to a new visible row
    rowcounter = rowcounter + 1
    CellColor = C.DisplayFormat.Interior.ColorIndex ' (works)
    If(cellColor = 38) Then ' Detects duplicate row
    MLSOne = ActiveCell.Value
    C.Offset(1,0).Select '
    MLSTwo = ActiveCell.Value
    C.Offset(-1,0).Select ' trying to get back to original duplicate row - does not[email protected] work
    C.Offset(0,19). ' Move to column that has deletion criteria -
    statusOne = ActiveCell.Value
    C.Offset(1,0).Select
    statusTwo = ActiveCell.Value
    C.Offset(-1,-19).Select ' want to move back to original 1st duplicate row
    rowindex = (Trim$((Str$(rowcounter)))
    If (MLSOne = MLSTwo) Then......CHecks for real duplicate and then moves to code to determine which row to delete

    Thanks for any comments/help,

    jarummel

  5. #5
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,885

    Re: Selecting columns using offset when there are hidden rows.

    Offset on visible cell only won't work, as offset is with cell context and does it regardless of visible state.

    One way to do it is... use For loop to loop until cell height > 0. But this is very inefficient way to do things.
    Ex:
    Please Login or Register  to view this content.
    If you upload sample file that represents your data set (sanitized) and exactly what should be the output/result...

    We can probably help you code something more efficient.

  6. #6
    Registered User
    Join Date
    11-23-2017
    Location
    Houston, TX
    MS-Off Ver
    2016 Pro
    Posts
    5

    Re: Selecting columns using offset when there are hidden rows.

    CK76,

    Thank you very much for the response. I was afraid that Offset was going to be the limiting factor. I like your recommendation of cell height and I will give it a try. I tried a similar approach using cell color to eliminate non-duplicates while using a full search of 100,000 plus records. Was very slow and that was why I was looking for a better approach. As I mentioned, I also had tried copying the duplicates to a new sheet (not including the underlying non-duplicates) but too many complications to integrate back into my main file. These are real estate transactions that I'm trying to keep up with on a monthly basis. Very difficult to sanitize these data, but thank you for the offer of looking at a better approach. By doing this on a monthly basis I have to track when the status of a property changes (e.g., from "Active" to "Sold"), thus the multiple duplicates.

    Thanks again, I'll let you know how the cell height approach works. I'll also look whether I can create a sanitized sub-set for further analysis.

    jarummel

  7. #7
    Registered User
    Join Date
    11-23-2017
    Location
    Houston, TX
    MS-Off Ver
    2016 Pro
    Posts
    5

    Re: Selecting columns using offset when there are hidden rows.

    CK76,

    After a lot of time trying different approaches, I went back to an earlier one that I had thought that worked. First, the conditional formatting is selected for duplicates. Second, I sort the table on the field (numeric) that has the duplicates. This is where I thought it wasn't working. Both the sort and the Excel program said they were not responding. Well, I had to leave the computer and when I came back (several hours later), it had sorted. I did some testing and it took approximately 30 minutes to complete. Because everything else has been so fast, I did not think to wait. My HP All-In-One does not have a disk status light so could not tell whether application had stopped. Then I sorted on color. Previously, I received the same "not responding" error messages. So, I let it sit and after about 15 minutes the sort came back with the ability to select the color and put on top. It took about 45 minutes to complete. I'm running Excel Pro Plus with 16GB on a 7th generation i7 processor and everything up to this point has been unbelievably fast (even when working many sheets, two large tables connected with a data model, and over 100,000 rows). With the speed I have been experiencing I never thought to wait. But the secret to bypass the hidden rows was to not use the filter function and just use sorting. BYW, I was able to use cell height but still ran into a problem with the overall approach.

    So, problem solved. Many thanks for taking the time and providing recommendations.

    jarummel

+ 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. Skip hidden columns when using offset
    By TechKnowledge in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-03-2016, 06:33 AM
  2. Ignore hidden rows when filtering and de-selecting range issue
    By dgibney in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-11-2014, 12:07 AM
  3. [SOLVED] Only selecting visible cells in a table with hidden rows
    By pfeifferjoey in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-02-2014, 09:22 AM
  4. [SOLVED] ActiveCell.Offset excluding hidden rows
    By sleepa in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-31-2013, 09:37 AM
  5. Skip hidden rows with offset
    By ainnocent1983 in forum Excel General
    Replies: 2
    Last Post: 03-08-2010, 11:57 AM
  6. selecting hidden columns
    By Jasonic in forum Excel General
    Replies: 2
    Last Post: 03-20-2009, 02:47 PM
  7. Keeping Hidden Rows/Columns Hidden?
    By DMac in forum Excel General
    Replies: 0
    Last Post: 01-17-2005, 08:13 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