+ Reply to Thread
Results 1 to 11 of 11

Macro to find specific text in a cell and then create multiple rows above

  1. #1
    Forum Contributor
    Join Date
    09-19-2012
    Location
    NYC
    MS-Off Ver
    Excel 2010
    Posts
    137

    Question Macro to find specific text in a cell and then create multiple rows above

    Can anyone help me to create a macro that finds a specific text string in the sheet and then creates 43 new rows above it? the text string only occurs once on the sheet. Additionally, i need each of the 43 newly created rows to to have "1" entered in cell A. The text is to find "Building Report 2"

    The idea is to be able add a new page to the first building report (above). I will copy the macro to each of 5 building report pages, changing the searched string to "Building Report 3", "4", etc. and link them to buttons on each report. Basically a separate identical macro in each one-page-long report that will add a blank page to that specific building report each time the user clicks the button at the bottom of the page.
    Last edited by Willardio; 09-21-2012 at 09:54 AM.

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Macro to find specific text in a cell and then create multiple rows above

    Please Login or Register  to view this content.
    if problem attach a sample file
    If solved remember to mark Thread as solved

  3. #3
    Forum Contributor
    Join Date
    09-19-2012
    Location
    NYC
    MS-Off Ver
    Excel 2010
    Posts
    137

    Re: Macro to find specific text in a cell and then create multiple rows above

    Thanks Patel, but it doesn't seem to do anything.

  4. #4
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: Macro to find specific text in a cell and then create multiple rows above

    In which column would you find the text "Building report 2" ?

    Also, do you want the macro to do the row insertion for building report 3,4,5,etc?
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  5. #5
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Macro to find specific text in a cell and then create multiple rows above

    Quote Originally Posted by Willardio View Post
    Thanks Patel, but it doesn't seem to do anything.
    attach a sample file

  6. #6
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,199

    Re: Macro to find specific text in a cell and then create multiple rows above

    Hi, Willardio,

    ... finds a specific text string in the sheet
    Maybe like this on one sheet:
    Please Login or Register  to view this content.
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  7. #7
    Forum Contributor
    Join Date
    09-19-2012
    Location
    NYC
    MS-Off Ver
    Excel 2010
    Posts
    137

    Re: Macro to find specific text in a cell and then create multiple rows above

    Thank you Holger, it works great... are you frequently called a genius?!

    I modified your code to insert the rows below the report after realizing it makes more sense with my filters. The only problem now is that the "1" does not appear in cell A of each new row. I need the 1's to protect the rows from my filter (not included in the sample) --if there another way to lock the rows from being filtered I'd be very interested in knowing that as well.

    Here is a sample of my sheet: br sample for adding a page.xlsm

    Here are my modifications to your code and the error message I am getting:

    Please Login or Register  to view this content.
    Thanks so much for your help so far!

    ~Willardio~
    Last edited by Cutter; 09-20-2012 at 08:28 PM. Reason: Added code tags

  8. #8
    Forum Contributor
    Join Date
    09-19-2012
    Location
    NYC
    MS-Off Ver
    Excel 2010
    Posts
    137

    Re: Macro to find specific text in a cell and then create multiple rows above

    "Building Report 2" appears in column B. I would rather have a seperate macro for each report because ease of use is essential. I plan to copy the code to a new macro for each report and link it to botton at the bottom of the page. Holger's code (see below) is good, only thing is that I don't get my "1" in cell A of each new line. the "1" is necessary to protect the rows from my filter.

    Here is a sample of my sheet: br sample for adding a page.xlsm

    Here is Holger's code with my modifications:

    Please Login or Register  to view this content.
    Last edited by Cutter; 09-20-2012 at 08:29 PM. Reason: Added code tags

  9. #9
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: Macro to find specific text in a cell and then create multiple rows above

    @ Willardio

    Welcome to the forum.

    Please notice that code tags have been added to your post(s). The forum rules require them so please keep that in mind and add them yourself whenever showing code in any of your future posts. To see instructions for applying them, click on the Forum Rules button at the top of the page and read Rule #3.
    Thanks.

  10. #10
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,199

    Re: Macro to find specific text in a cell and then create multiple rows above

    Hi, Willardio,

    try it with this modified code which worked fine on your copy of the workbook:

    Please Login or Register  to view this content.
    Ciao,
    Holger

  11. #11
    Forum Contributor
    Join Date
    09-19-2012
    Location
    NYC
    MS-Off Ver
    Excel 2010
    Posts
    137

    Re: Macro to find specific text in a cell and then create multiple rows above

    Holger, what are you? Some kind of uber-rockstar or something?? You must be 8 feet tall! Thanks for solving all my Excel problems!

    I modified it a little and it works perfectly. Here's the functional sample workbook:

    br sample for adding a page SOLVED.xlsm

    And the modified code:

    Please Login or Register  to view this content.
    Now if only I could get a macro to apply my filter to work in protected mode... I guess it's already time for a new thread.

    Thanks again for your excellent efforts!

    ~Willardio

+ 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