+ Reply to Thread
Results 1 to 6 of 6

macro to find text heading then select underlying data?

  1. #1
    Registered User
    Join Date
    12-13-2006
    Posts
    27

    macro to find text heading then select underlying data?

    Hi, I don't expect a solution for this, but it would be great to know if it might be possible. Looking at the attached worksheet, would it be possible to search for a text heading (i.e. Group A) and then select all rows and columns underneath that heading until there is an empty cell?

    The format of my actual data extract is just like this, where the text heading is listed, then dashes below, then data. The amount of rows will vary, that's why I hope to select all for each keyword until an empty row appears.

    If it is possible to find and select that data, I then want to cut and past in a new worksheet tab.

    thanks for any input!
    Attached Files Attached Files

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: macro to find text heading then select underlying data?

    Searching for "Group A" is simple and selecting all the data in the range of cells attached to that cell is also pretty simple. What you left out was what to DO with that once it is found.

    This little macro will find your search string, and copy the data set to sheet2.
    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 08-06-2011 at 01:38 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!)

  3. #3
    Forum Contributor
    Join Date
    12-26-2010
    Location
    Kansas City, Kansas
    MS-Off Ver
    Excel 2007
    Posts
    147

    Re: macro to find text heading then select underlying data?

    Hi
    .
    You will have to save your file as an Excel Macro file.
    .
    Then you will have to add a module for putting code in.
    .
    Note: There are general modules and Class modules.
    You want to add a General module in that the code below
    is for a general module.
    .
    Based on your original Excel file I have made the assumption that all data
    blocks begin with the word GROUP e.g. Group A , Group B etc.
    .
    If that assumption is NOT true then the code below will fail.
    .
    Please note the following about the code below:

    * Alot of it will seem like gibberish. Just ignore most of it and look for a
    subroutine called PUBLIC SUB MAIN. Once you have found it - put your
    cursor in it and run it using the F8 key or the Shift F8 to by pass going into
    lower sub routines.

    * It is "more correct" to use local variables in a sub-routine but I not done this
    and created properties for various counts and other thingies. They are being
    used in place of local variables.

    * I tested the code by (1) using what you had and (2) adding additional GROUPS
    with various # of blank lines between them and the code seems to work,
    .
    BUT - the code assumes that the KEY WORD GROUP is **always** there
    and **always** in the 1st column.

    * This code is NOT elegant or the fastest way to do it - but its the way
    I think. -g-
    .
    Just copy and paste the code below into the module I described above.
    .
    As in your example - I ASSUME data is in SHEET1 and you want to
    write to SHEET2. (You can change this in the code if required)
    .
    HTH
    regards
    John

    Please Login or Register  to view this content.

  4. #4
    Valued Forum Contributor gjlindn's Avatar
    Join Date
    08-01-2011
    Location
    Dodgeville, WI
    MS-Off Ver
    Excel 2003, 2007, 2010, 2013
    Posts
    369

    Re: macro to find text heading then select underlying data?

    I'm betting you're looking for something like this.
    Please Login or Register  to view this content.
    Attached Files Attached Files
    -Greg If this is helpful, pls click Star icon in lower left corner

  5. #5
    Forum Contributor
    Join Date
    12-26-2010
    Location
    Kansas City, Kansas
    MS-Off Ver
    Excel 2007
    Posts
    147

    Re: macro to find text heading then select underlying data?

    Hi
    I woke up this morning and realized that what I posted is NOT what you wanted.
    Very simply (if I am correct) you are simply trying to write the FINANCIAL DATA ONLY
    to another worksheet.
    Additionally, I am assuming that you WANT the column headings.
    If these assumptions are correct - then here is the revised code.
    HTH
    regards
    John
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    12-13-2006
    Posts
    27

    Re: macro to find text heading then select underlying data?

    Thanks all for the feedback. I will try out some of these suggestions.

    Thank you

+ 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