+ Reply to Thread
Results 1 to 13 of 13

Macro for seaching a phrase and add 7 rows after that phrase

  1. #1
    Registered User
    Join Date
    10-20-2014
    Location
    SG
    MS-Off Ver
    2010
    Posts
    13

    Macro for seaching a phrase and add 7 rows after that phrase

    Dear all,

    I have a question and hope someone could help save me from it.

    I need to create a macro to find the phrase "I Love You" in an excel worksheet column B.
    However, this seleceted phrase always appear in different rows depending on the month.

    After the macro helped seaching the phrase "I Love You", i need to insert 7additional rows below it.


    In conclusion, is there anyone that knows the macro to search the phrase "I Love You" in column B (but the row that the phrase will be located in differ).
    after searching the phrase, the macro would also help adding 7 rows below it.


    thank you very much in advance.

  2. #2
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,596

    Re: Macro for seaching a phrase and add 7 rows after that phrase

    Select range (or column) and run this macro:

    It will prompt you for phrase so you can type whatever and then run.

    Please Login or Register  to view this content.
    It will end after first match.
    If you want to add 7 rows after each match remove "Exit Sub" part

  3. #3
    Registered User
    Join Date
    10-20-2014
    Location
    SG
    MS-Off Ver
    2010
    Posts
    13

    Re: Macro for seaching a phrase and add 7 rows after that phrase

    hi zbor,

    Thank you so much for you help.
    i tried running the macro, however, it is able to find the phrase i am looking for when the macro prompt me.

    when you said "select range or column and this run macro" what do you mean by that?
    sorry that i am totally new to macros

    sorry and thank you.

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2404 Win 11 Home 64 Bit
    Posts
    23,865

    Re: Macro for seaching a phrase and add 7 rows after that phrase

    Try this:

    Please Login or Register  to view this content.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  5. #5
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,596

    Re: Macro for seaching a phrase and add 7 rows after that phrase

    Select range.. Like put pointer on some cell, click left button on the mouse and drag down...
    So cells become blue. You can select also whole (B) column by pressing B at the top of the sheet

    pattern-dragged-down.png

    Then run macro.

  6. #6
    Registered User
    Join Date
    10-20-2014
    Location
    SG
    MS-Off Ver
    2010
    Posts
    13

    Re: Macro for seaching a phrase and add 7 rows after that phrase

    thank you guys!

    your macro work wonders, like magic. its my first time doing macro though. i am so amazed by it
    by the way, the 7 rows that is added in after i run the macro will only add to the particular column below the phase.
    i need the rows to add across worksheet.
    i think this is becaused my worksheet has merged cells.

    are there any ways that i could add the rows across the worksheet and not affecting the merged cells below?

    thank you so much my saviour.

  7. #7
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2404 Win 11 Home 64 Bit
    Posts
    23,865

    Re: Macro for seaching a phrase and add 7 rows after that phrase

    VBA does not play well with merged cells. Can you change your layout to avoid using merged cells? Otherwise, you may have to add vba steps to unmerge your cells, run your code and then re-merge your cells. This may or may not give you the expected results. Personally, I avoid merging cells especially if I am working in a VBA environment.

  8. #8
    Registered User
    Join Date
    10-20-2014
    Location
    SG
    MS-Off Ver
    2010
    Posts
    13

    Re: Macro for seaching a phrase and add 7 rows after that phrase

    i had unmerged the cells. however, the rows still do not add acorss the whole worsheet but only added below the column with my selected phrase

  9. #9
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,596

    Re: Macro for seaching a phrase and add 7 rows after that phrase

    Use this for entire row:

    Please Login or Register  to view this content.

  10. #10
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Macro for seaching a phrase and add 7 rows after that phrase

    Another:

    Please Login or Register  to view this content.

  11. #11
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2404 Win 11 Home 64 Bit
    Posts
    23,865

    Re: Macro for seaching a phrase and add 7 rows after that phrase

    Did you try the code I supplied in post 4 as it worked for me when I tested.

  12. #12
    Registered User
    Join Date
    10-20-2014
    Location
    SG
    MS-Off Ver
    2010
    Posts
    13

    Re: Macro for seaching a phrase and add 7 rows after that phrase

    Thank you guys so much, i tried the macros and all of them worked wonders.

    I managed to insert 7 rows successfully thanks to your help!

    I'm currently using the code provided by John H. Davis as it is less complicated for a newbie like me, however, the other codes worked well too, i've tried them already

    Thank you all once again for all the quick response!

  13. #13
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2404 Win 11 Home 64 Bit
    Posts
    23,865

    Re: Macro for seaching a phrase and add 7 rows after that phrase

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks for the rep.

+ 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. Replies: 2
    Last Post: 10-09-2014, 05:14 AM
  2. Mass Delete Rows with specific phrase
    By washburn321 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-26-2014, 10:50 AM
  3. [SOLVED] Remove Rows With Specific Phrase Using Another Worksheet
    By AccountNameHere in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 08-08-2013, 07:00 PM
  4. Hiding Rows With A Cell Containing Specific Phrase
    By carrleaston in forum Excel General
    Replies: 1
    Last Post: 10-31-2011, 07:24 PM
  5. Function to return text from phrase X to phrase Y
    By razr in forum Excel General
    Replies: 3
    Last Post: 05-06-2009, 05:52 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