+ Reply to Thread
Results 1 to 9 of 9

Macro to search for a word and copy the row containing it to another worksheet

  1. #1
    Registered User
    Join Date
    11-15-2013
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    41

    Macro to search for a word and copy the row containing it to another worksheet

    Hi,

    I'm trying to write a code that will search the row for the word "Novartis". If the row contains the word - it will be the first column that will contain it - the whole row will be copied to another worksheet.

    The first worksheet (one where we are searching for the word) is called "Consolidation" and the second worksheet is called "Novartis" - this is the worksheet we are copying the row to.

    Here is my code:

    Please Login or Register  to view this content.
    Whenever I try to run the macro, I come up with an error telling me Error 424 The object is not defined, with the row of code starting with erow highlighted, or an error saying Can't execute code in break mode.

    Can anybody see what is wrong with my code?

  2. #2
    Forum Contributor
    Join Date
    03-12-2013
    Location
    Chicago, USA
    MS-Off Ver
    Excel 2007
    Posts
    230

    Re: Macro to search for a word and copy the row containing it to another worksheet

    You may need to define x as a variable. Add this to the beginning:
    Please Login or Register  to view this content.

  3. #3
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2504 Win 11
    Posts
    24,691

    Re: Macro to search for a word and copy the row containing it to another worksheet

    Try the following:

    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

  4. #4
    Forum Expert
    Join Date
    02-22-2013
    Location
    London, UK
    MS-Off Ver
    Office 365
    Posts
    1,218

    Re: Macro to search for a word and copy the row containing it to another worksheet

    Another way:

    Please Login or Register  to view this content.

  5. #5
    Forum Expert
    Join Date
    02-22-2013
    Location
    London, UK
    MS-Off Ver
    Office 365
    Posts
    1,218

    Re: Macro to search for a word and copy the row containing it to another worksheet

    Quote Originally Posted by alansidman View Post
    Try the following:

    Please Login or Register  to view this content.
    I had just written a solution when I saw this post, so I posted it too, although I am sure this does the trick

  6. #6
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2504 Win 11
    Posts
    24,691

    Re: Macro to search for a word and copy the row containing it to another worksheet

    Yup. They both look like they will do it. What I like is that VBA writers all have a different style and there is no one absolute way to get to the same solution.

  7. #7
    Forum Expert
    Join Date
    02-22-2013
    Location
    London, UK
    MS-Off Ver
    Office 365
    Posts
    1,218

    Re: Macro to search for a word and copy the row containing it to another worksheet

    So true alansidman! I think it can be really exciting to see how other VBA writers (often more experienced then me) attempts to solve the very same problem, their valued inputs and unique style.

  8. #8
    Registered User
    Join Date
    11-15-2013
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    41

    Re: Macro to search for a word and copy the row containing it to another worksheet

    FANTASTIC, they both worked, thank you so much!!

  9. #9
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2504 Win 11
    Posts
    24,691

    Re: Macro to search for a word and copy the row containing it to another worksheet

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

+ 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: 8
    Last Post: 11-04-2013, 02:34 PM
  2. Macro to copy worksheet content row by row to Word document
    By rkh_11 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 12-13-2010, 06:19 AM
  3. Macro to Search column and if found, copy a cell within the worksheet
    By SKooT1027 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-16-2008, 01:12 PM
  4. Macro to copy worksheet into word
    By cannon_lab in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-21-2008, 08:01 PM
  5. search for a specific word and copy the word and the preceeding words until a comma
    By DHANANJAY in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 12-31-2005, 09:10 AM

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