+ Reply to Thread
Results 1 to 8 of 8

Copy rows to another sheet if any cell in the row contains a certain word

  1. #1
    Registered User
    Join Date
    09-02-2013
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    4

    Copy rows to another sheet if any cell in the row contains a certain word

    Hi there, I'm new to Macros/VBA and to this forum too so I would be grateful if people could use language that I would understand!

    I have a database of about 6000 patients with their details (name, DOB etc.) and their diagnoses (Addisons, Turners etc,). These diagnoses come under the umbrella of the organ they are associated with. For example, Addisons is a problem with the adrenal gland and Turners is a problem with the ovaries. Some patients have multiple diagnoses with one organ, or even multiple diagnoses with multiple organs.

    My job is to create new sheets from this 'master sheet' containing only patients with adrenal problems in one sheet and only patients with ovary problems in another and so on and so forth for each organ. It is also important that patients who have problems in multiple organs appear in each respective sheet. E.g. a person with adrenal issues appears in the adrenal sheet and if they have ovary issues they also appear in the ovary sheet.

    I've attached an excerpt from the database and for obvious reasons I have replaced the confidential information. If you notice, not all of the columns are full, which I hope ought not to be an issue and also some patients which are a work in progress don't have a diagnosis and as such they are labelled with an 'X' in the first diagnosis column. Moreover, some patients will not have a diagnosis and will be labelled with the tags UNDIAGNOSED and/or DISCHARGED.

    Basically I need to copy whole rows containing the word 'ADRENAL' into the sheet labelled 'Adrenal.' And again with the other organs as well. It's important that the whole row containing all of the patient information is copied along with the diagnoses.

    I imagine that I would need a macro for each organ....but I literally don't know anything about macros/VBA so I shall stop guessing!

    I have attempted to read other threads but I find it all very confusing, hopefully by talking about my example specifically I will get it.

    Sorry for the long message but I wanted to be thorough and hopefully I have been. Reply if any other information is required. I will endeavour to reply ASAP but as I'm sure you can imagine, doctors don't get a lot of free time!

    Kind Regards

    P.S. I forgot to mention that ideally the codes would also work for future data being entered as I intend on expanding the database.
    Template Original.xlsx
    Last edited by theavkid; 09-02-2013 at 10:47 AM.

  2. #2
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: Copy rows to another sheet if any cell in the row contains a certain word

    Hello Thea,

    See if this works?

    First you need a macro that will filter the organs and copy them to its respective sheets.

    Please Login or Register  to view this content.
    and then a code to go through all the sheets pasting what was filtered.

    Please Login or Register  to view this content.
    The only code you have to run is the second one. Put them both in a same module.

    I have attached a file for you to see. Attachment 262413

  3. #3
    Registered User
    Join Date
    09-02-2013
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Copy rows to another sheet if any cell in the row contains a certain word

    Thanks for the reply fredlo2010!

    It works perfectly! You are a godsend, haha!

    Appreciate it so much, this is going to save so much time!

  4. #4
    Registered User
    Join Date
    09-02-2013
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Copy rows to another sheet if any cell in the row contains a certain word

    Quote Originally Posted by fredlo2010 View Post
    Hello Thea,

    See if this works?

    First you need a macro that will filter the organs and copy them to its respective sheets.

    Please Login or Register  to view this content.
    and then a code to go through all the sheets pasting what was filtered.

    Please Login or Register  to view this content.
    The only code you have to run is the second one. Put them both in a same module.

    I have attached a file for you to see. Attachment 262413
    I have one query though. I have noticed that some people with Thyroid problems in the master sheet don't appear in the Thyroid specific sheet. I am not sure if this is because the word 'Thyroid' doesn't appear in the first Diagnostics column (D1). Is there a way of getting patients with umbrella labels like that no matter what column they appear in, to appear in the respective organ sheet.

    Thank you!

  5. #5
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: Copy rows to another sheet if any cell in the row contains a certain word

    you are right let me see how I can solve this .

  6. #6
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: Copy rows to another sheet if any cell in the row contains a certain word

    Thea,

    I think we got it this time.

    this is the function
    Please Login or Register  to view this content.
    and the main code

    Please Login or Register  to view this content.
    Thanks

  7. #7
    Registered User
    Join Date
    09-02-2013
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Copy rows to another sheet if any cell in the row contains a certain word

    Thanks so much! It works really well. I appreciate it so much. I don't understand the code at all but so long as it works. If I had more time, I'd love to be able to learn more about it as I'm sure it would save me so much time in all of my excel projects!

    Thanks again

  8. #8
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: Copy rows to another sheet if any cell in the row contains a certain word

    I am glad it helped you

+ 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. Copy table row to another sheet when a specific cell contains the right word
    By robclark89 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-17-2013, 09:53 PM
  2. [SOLVED] Code to copy numerous sheet cell ranges to a word document on my desktop
    By matrixpom in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-21-2013, 07:48 PM
  3. copy rows from sheet using a template to a word file
    By lightningt12312 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 04-09-2009, 06:21 AM
  4. Copy Rows from selected Sheet to New Sheet based on Cell Value
    By joemcmillen in forum Excel Programming / VBA / Macros
    Replies: 24
    Last Post: 04-03-2008, 03:44 PM
  5. Copy rows from excel sheet to a word document
    By ashishprem in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-27-2006, 08:55 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