+ Reply to Thread
Results 1 to 6 of 6

Selecting Groups of Similar Data

  1. #1
    Valued Forum Contributor
    Join Date
    11-20-2003
    MS-Off Ver
    2010, 2016
    Posts
    1,173

    Selecting Groups of Similar Data

    I have ~1,000 rows of data utilizing columns A:C. The data is "grouped" by data that is in column C. Layout is as follows for example

    Row01.....Column A......Column B.......Column C
    Row02.....some data.....some data.....apples
    Row03.....some data.....some data.....apples
    Row04.....some data.....some data.....apples
    Row05.....some data.....some data.....apples
    Row06.....some data.....some data.....oranges
    Row07.....some data.....some data.....oranges
    Row08.....some data.....some data.....oranges
    Row09.....some data.....some data.....oranges
    Row10.....some data.....some data.....pears
    Row11.....some data.....some data.....pears
    Row12.....some data.....some data.....pears

    I have been trying to come up with some code that will "select" groups of data and then perform an action on those cells.

    As an example
    Please Login or Register  to view this content.
    Thanks in advance for any suggestions.
    Last edited by maacmaac; 08-05-2009 at 06:22 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,258

    Re: Selecting Groups of Similar Data

    Hello maacmaac,

    Are all the groups always together as in your example? All apples together, etc.
    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
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Selecting Groups of Similar Data

    It looks like you're actually trying to grab all the rows of data that match the fruit in column C. Have you ever used an AutoFilter? That's what it does. And you can do actions on the filtered data, too.

    Further, with an autofilter, it won't matter that all pears/apples/oranges aren't altogether in the data set. An autofilter hides all rows that don't fit the criteria and you can grab the visible data to do stuff.
    Please Login or Register  to view this content.
    Here's an example of a loop that goes through an array of fruits.

    Please Login or Register  to view this content.
    =======
    LAstly, notice my code isn't "selecting" cells before copying or whatever else you're going to do to it? Get in the habit of NOT selecting, it's 90% of the time a wasted step and unnecessary.
    Last edited by JBeaucaire; 08-05-2009 at 01:51 AM.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  4. #4
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885

    Re: Selecting Groups of Similar Data

    As an example, a way to select each group could be done this way:
    Please Login or Register  to view this content.
    Rather than selecting that range, you could obviously perform some other code to it or to adjacent ranges.

  5. #5
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Selecting Groups of Similar Data

    Use AutoFilter on column C, hen perfor the action on the filtered range.

    This can be automated with VBA - use the macro Recorder to start or there's lots of autofilter code on the forum, I've posted seversl examples
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  6. #6
    Valued Forum Contributor
    Join Date
    11-20-2003
    MS-Off Ver
    2010, 2016
    Posts
    1,173

    Re: Selecting Groups of Similar Data

    Wow!!! Never expected so many repsonses to one question. Thank you, thank you, thank you. Leith...to your question, the data is always grouped together. Completed testing of both codes presented and both work as expected. Plus a lot of good information in other threads about autofilter.
    Last edited by maacmaac; 08-05-2009 at 06:22 PM. Reason: Tested solutions presented.

+ 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