+ Reply to Thread
Results 1 to 10 of 10

Find "single row" and delete them

  1. #1
    Registered User
    Join Date
    07-13-2009
    Location
    NYC, USA
    MS-Off Ver
    Excel 2007
    Posts
    5

    Find "single row" and delete them

    Hi everyone,
    I am pretty new to Excel - but I have a little programming experience.
    Anyway, I am stuck and could need help.

    I tried to write a script that does following:


    I have data that looks like this:

    1
    1
    2
    2
    3
    3
    4
    5
    5
    6
    6

    As you can see, mostly every two rows contain same values.
    But there are some values (here it is 4) that is a "single row".

    I want to find every "single row" and delete them.
    I tried a long time but reached frustration now
    I hope someone can help me.
    My script is below.
    Thank You!


    Please Login or Register  to view this content.
    Last edited by jk@CU; 07-15-2009 at 06:52 PM.

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

    Re: Find "single row" and delete them

    Hello jk@CU,

    Here is version similar to yours. The Dictionary object is an Associative Array. This makes it faster and easier to reference the elements because of the Exists method. This will tell you if an element is already in the array. The additional advantage over a regular array is the index or "key" can be any of any data type as can the contents or "item" except a User Define Type.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    07-13-2009
    Location
    NYC, USA
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Find "single row" and delete them

    Hi Leith!

    That not only works, but also seam to contain some I can learn


    Thank You!

  4. #4
    Registered User
    Join Date
    07-13-2009
    Location
    NYC, USA
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Find "single row" and delete them

    Hi Leith and everyone,

    Sadly I recognized, that that macro makes some kind of mistake
    1.) It does not delete every "single-value-row"
    2.) However it seems to delete too many rows
    3.) I could not apply that macro to a selection of a huge number of rows
    (e.g. 4000)

    I will definitely work on a solution - If someone else is interested to do so before I would be very grateful

    I will attach an excel file (without the two macro-versions above).
    It contains two columns, the first is the "ID" of a person (here person 13 and 14), the second column contains the values I would like to filter for.

    Best, Johann
    Attached Files Attached Files
    Last edited by jk@CU; 07-14-2009 at 06:57 PM.

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Find "single row" and delete them

    I just used a minor variation of Leith's code on 10,000 rows, and it worked perfectly. Post a workbook where it doesn't work.
    Entia non sunt multiplicanda sine necessitate

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

    Re: Find "single row" and delete them

    Hello jk@CU,

    Please post examples that represent to the ACTUAL data layout and format. The macro works as it should. The problem is you failed to mention that another variable Var1 needed to be considered. I discovered this after manually examining all the cells you wanted to check. I will post back with a macro that takes this new variable into consideration.

  7. #7
    Registered User
    Join Date
    07-13-2009
    Location
    NYC, USA
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Find "single row" and delete them

    Wow, that would be great!
    (Feels like Christmas for the way home after a long day...)

    Thank You!

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

    Re: Find "single row" and delete them

    Hello jk@CU,

    I have finished the new macro. It is setup to allow you to verify its accuracy by coloring all the unique entry cells in column "B" yellow. The macro will display a dialog showing the count of unique cells found and ask if you want to delete the cells' rows.

    The macro now creates a Dictionary object for the groups of data based on the value of the cell in column "A". The data in column "B" is added to this group as a new Dictionary object which in turns holds a Range reference to the cell in column "B". Whenever a second reference to the data in a group is found, the data Range reference is set to Nothing. This makes it easy to then create a Range of only unique cells to be deleted. The macro below has been added to the attached workbook. Let me know how this works out.
    Please Login or Register  to view this content.
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    07-13-2009
    Location
    NYC, USA
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Find "single row" and delete them

    Hi Leith!

    Your script is great!
    Actually the addition of marking the cells yellow is very helpful, since I in deed want to have a close look on the rows, that are "single".
    After your support I want to give an idea, where your script is helping.

    For my masterthesis in Psychology I want to analyze the output data of an eye tracker to correlate eye movement behavior with personality traits.
    The participants are presented pictoral stimuli on the screen while having their eyes monitored.

    The first column represents the participant. For each presentation of a stimulus on the computer screen, called "trial" I have two rows.
    The first row checks if the participant was looking on the central fixation cross before the stimulus onset, the second row checks if the participant did look on certain areas of the stimulus.
    So all the "single" rows mean, that the participant did not have both of those conditions in that trial.
    That's why that "single" rows have to be dismissed.

    With your script I even can have a much more comfortable look at the "bad" trials. Which means a lot, since I have many many thousands of rows - and I will have to check the data with different settings over and over again...

    ...So many thanks to your help, I am very happy with your scipt

    Best,
    Johann

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

    Re: Find "single row" and delete them

    Hello Johann ,

    I am glad this version meets your needs. My wife is a psychologist (MFT). I would love to hear more about this as your studies progress. Rapid eye movement desensitization for the treatment of PTSD is a remarkable tool. If your research can help identify personality types by tracking eye movement behaviour, that would be another leap forward in the field. Good luck and stay in contact.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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