+ Reply to Thread
Results 1 to 33 of 33

Pasting entire row to a new sheet if cell contains certain text

  1. #1
    Registered User
    Join Date
    06-29-2014
    Location
    London
    MS-Off Ver
    2007
    Posts
    15

    Pasting entire row to a new sheet if cell contains certain text

    Hi there,

    I am looking at trying to develop a workbook for my job that would make things alot more efficient. This involves a few things that i am hoping to get some help with.

    Firstly, I download data from a web based app into excel. I now want to take certain full rows and paste them into another sheet depending if they have certain text in a cell. So i want to search the entire coloumn for a value of "OR" and if this is present copy the entire row into a new sheet ?

    Does this make sense and is it possible?

    Thanks

    Mark
    Last edited by bakerbaz04; 06-29-2014 at 09:41 AM.

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

    Re: Newbie requring help

    Hi, Mark,

    welcome to ExcelForum. Please have a look at Forum Rule #1 and change the thread title according to this rule.

    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

  3. #3
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,446

    Re: Newbie requring help

    Hi
    to make a better chance of getting an answer, please adapt your thread title per forum rules - Thx

  4. #4
    Registered User
    Join Date
    06-29-2014
    Location
    London
    MS-Off Ver
    2007
    Posts
    15

    Re: Pasting entire row to a new sheet if cell contains certain text

    Apologies, Hope this is sufficient

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

    Re: Pasting entire row to a new sheet if cell contains certain text

    Hi, Mark,

    if the range shows headers in the first row you could use the Advanced Filter with both Criteria range as a well as Output on a different sheet starting the Filter from that sheet. This would copy over all rows which meet the criteria.

    If you want to apply VBA you should consider to use the Autrofilter and narrow down the number of row to just those that fit, check if any records are listed and copy over the visible range to the destination sheet.

    The last and most time consuming way would be to run a loop over all the records and compare each cell froma column in every row to match the criteria. If so, copy over the row to the destination sheet.

    You may record the action you take with the macro recorder (make sure that the developer tab is made visible via Options) and take that code as a start which would need some work as the macro recorder usually hard-codes all ranges and needs to Select before taking any action to cells/ranges (which you will not if youīre writing the code on the scratch).

    Ciao,
    Holger
    Last edited by HaHoBe; 06-29-2014 at 12:07 PM. Reason: corrected name

  6. #6
    Registered User
    Join Date
    06-29-2014
    Location
    London
    MS-Off Ver
    2007
    Posts
    15

    Re: Pasting entire row to a new sheet if cell contains certain text

    Without trying to sound ignorant (its been 10 years since i used VBA/macros) is the range just defined as the cells you wanted to check? so if i wanted to check the entirety of Column F, the range would be F:F?

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

    Re: Pasting entire row to a new sheet if cell contains certain text

    Hi, bakerbaz04,

    maybe use
    Please Login or Register  to view this content.
    to check the cells below the header to the very last filled cell in Column F.

    Ciao,
    Holger

  8. #8
    Registered User
    Join Date
    06-29-2014
    Location
    London
    MS-Off Ver
    2007
    Posts
    15

    Re: Pasting entire row to a new sheet if cell contains certain text

    Holger,

    What code do I put in to search the range for the text "OY", then paste this entire row into new sheet if "OY" is present ?

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

    Re: Pasting entire row to a new sheet if cell contains certain text

    Hi, Mark,

    you would need to narrow down the question if the item is the whole content of the cells or a part of it.

    Please Login or Register  to view this content.
    If you want to search for a part of the cell you could use
    Please Login or Register  to view this content.
    or use InStr to find out the first position of a possible match in the characters of the cell.

    Ciao,
    HOlger

  10. #10
    Registered User
    Join Date
    06-29-2014
    Location
    London
    MS-Off Ver
    2007
    Posts
    15

    Re: Pasting entire row to a new sheet if cell contains certain text

    So basically this is what i want to acheive ...


    Consist Assest Defect Code

    BN01 12456 UI
    BN08 12457 OY
    BN24 11232 EJ


    I would want the whole 2nd row to be pasted into a new sheet. then any other rows with OY in the "Defect Code" coloumn to also be pasted into a new sheet, i will then be wanting different defect codes to be pasted to different sheets?

    Regards

    Mark

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

    Re: Pasting entire row to a new sheet if cell contains certain text

    Hi, Mark,

    depending on how many items you want to find and the names of the sheets you could use either a Select Case if the item is the whole contents you could apply the destination name to a variable and use that for copying.

    I would suggest to use two arrays (one holding the items to find, one for the sheets to copy to), use the Autofilter and copy over the visible area and either add beneath whatīs already on the sheets or delete the data on eahc shirt and then add..

    Ciao,
    Holger

  12. #12
    Registered User
    Join Date
    06-29-2014
    Location
    London
    MS-Off Ver
    2007
    Posts
    15

    Re: Pasting entire row to a new sheet if cell contains certain text

    Holger,

    using to arrays sounds good, where do i start? apprecitate your help and apoogies for being a pain.

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

    Re: Pasting entire row to a new sheet if cell contains certain text

    Hi, Mark,

    could be solved like this:
    Please Login or Register  to view this content.
    Ciao,
    Holger

  14. #14
    Registered User
    Join Date
    06-29-2014
    Location
    London
    MS-Off Ver
    2007
    Posts
    15

    Re: Pasting entire row to a new sheet if cell contains certain text

    Its giving me an erro message around the Set wsData=Sheets(cstrDATA)

    I should mention that i have the raw data in sheet 1 and want to paste it into sheet 2, onve i have this sussed i can assign it to a button and make the interface more friendly

    Cheers

  15. #15
    Registered User
    Join Date
    06-29-2014
    Location
    London
    MS-Off Ver
    2007
    Posts
    15

    Re: Pasting entire row to a new sheet if cell contains certain text

    Its giving me an erro message around the Set wsData=Sheets(cstrDATA)

    I should mention that i have the raw data in sheet 1 and want to paste it into sheet 2, onve i have this sussed i can assign it to a button and make the interface more friendly

    Cheers

  16. #16
    Registered User
    Join Date
    06-29-2014
    Location
    London
    MS-Off Ver
    2007
    Posts
    15

    Re: Pasting entire row to a new sheet if cell contains certain text

    error 9;

    Subscript out of range

  17. #17
    Registered User
    Join Date
    06-29-2014
    Location
    London
    MS-Off Ver
    2007
    Posts
    15

    Re: Pasting entire row to a new sheet if cell contains certain text

    error 9;

    Subscript out of range

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

    Re: Pasting entire row to a new sheet if cell contains certain text

    Hi, Mark,

    you would need to change the name of the constant to suit your needs for the sheet which holds the data - I havenīt seen anything from your workbook so Iīm off to guess, and I may assure you that I ran the code in a sample workbook in Excel2013 and the code didnīt raise an error before posting the code here.

    Ciao,
    Holger

  19. #19
    Registered User
    Join Date
    06-29-2014
    Location
    London
    MS-Off Ver
    2007
    Posts
    15

    Re: Pasting entire row to a new sheet if cell contains certain text

    Can i upload a sample for you ? how do i do that

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

    Re: Pasting entire row to a new sheet if cell contains certain text

    Hi, Mark,

    Remember to desensitize the data in the workbook.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic
    Ciao,
    Holger

  21. #21
    Registered User
    Join Date
    06-29-2014
    Location
    London
    MS-Off Ver
    2007
    Posts
    15

    Re: Pasting entire row to a new sheet if cell contains certain text

    Prototype1.xlsx

    Hopefully this has worked, so basically i want to copy and paste anything with an O in column F into the "Doors" sheet, if a "UW" is present in column F paste entire row into "Wheels" sheet, and if "CHECK" is present in column E paste entire row into "Checks" sheet.

    then i want to assign this to a command button.

    Hope this makes sense

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

    Re: Pasting entire row to a new sheet if cell contains certain text

    Hi, Mark,

    what should happen with rows 41 ansd 42 as they meet both the criteria in Column F as well in Column E, should these lines be copied to both sheets? And there is a problem with all the rows you marked yellow as I donīt see any reason for rows 16 or 88-95 to be marked.

    Using some simple additions like headers in the first row of data would enable you to use a better method than looping through all the data but I mentioned that way before in this post. So again: this canīt be the fastest of all codes as you by now explain that you will need to check to two Columns independly on each other and start your data on the first row.

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

  23. #23
    Registered User
    Join Date
    06-29-2014
    Location
    London
    MS-Off Ver
    2007
    Posts
    15

    Re: Pasting entire row to a new sheet if cell contains certain text

    Holger that is fantastic,

    apologies on the "Check" sheet there was not supposed to be any raw data in that sheet but i forgot to delete this. If the both are contained in one row then yes i would prefer if the row could be pasted to both sheets if this is possible? I am going to edit headers now for the columns to make this easier

  24. #24
    Registered User
    Join Date
    06-29-2014
    Location
    London
    MS-Off Ver
    2007
    Posts
    15

    Re: Pasting entire row to a new sheet if cell contains certain text

    Also im not sure if this is possible but can i run a seperate macro attached to a command button to clear these sheets? as the raw data will change depending on when i download it? Would of loved to of created a macro for the download side of this process but seems this cant be done

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

    Re: Pasting entire row to a new sheet if cell contains certain text

    Hi, Mark,

    Please Login or Register  to view this content.
    Yes to the next 2 questions in general but lacking of information you should consider to start a new thread and be more precise than
    Would of loved to of created a macro for the download side of this process but seems this cant be done
    The Magic Ball is broken, and thereīs a lot of snow but very little exact information on what to download from where, how to do so, where to store, how and if to smoothen the data if needed.

    Ciao,
    Holger

  26. #26
    Registered User
    Join Date
    06-29-2014
    Location
    London
    MS-Off Ver
    2007
    Posts
    15

    Re: Pasting entire row to a new sheet if cell contains certain text

    Thanks Holger

    Do I input that code as a seperate macro or incorporate into the existing "run me" button?

    I will start a new thread shortly for the other issues. You guys really are incredible.

    Many thanks

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

    Re: Pasting entire row to a new sheet if cell contains certain text

    Hi, bakerbaz04,

    sorry I didnīt find any button in the workbook - if all three macros were part of the button I would comment out the original text and assign the last posted procedure to that button,. If any other modification is made in that button I would use a different button and name it accordingly (or think about implementing an own Tab into the ribbon to hold the macros related to the workbook which would need some XML-Code to do so and an external UI Editor).

    Ciao,
    Holger

  28. #28
    Registered User
    Join Date
    06-29-2014
    Location
    London
    MS-Off Ver
    2007
    Posts
    15

    Re: Pasting entire row to a new sheet if cell contains certain text

    Holger,

    Sorry I confused that,

    What I meant was; if I wanted to put anything with check and UW in both sheets, do I need to input the code into the macro you assigned to the "run me" button.

    As it turns out I would just like the ones that meet both criteria into the checks sheet, so if a row has UW and Checks it would only paste to the Checks sheet. Is there anything I need to Alter to acheive that ?

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

    Re: Pasting entire row to a new sheet if cell contains certain text

    Hi, Mark,

    if I read the code correctly I would say that the code from http://www.excelforum.com/excel-prog...ml#post3751763 should do what you want.

    Ciao,
    Holger

  30. #30
    Registered User
    Join Date
    06-29-2014
    Location
    London
    MS-Off Ver
    2007
    Posts
    15

    Re: Pasting entire row to a new sheet if cell contains certain text

    Holger,

    This code works fantatsically well, appreciate all your help, one last question, if i wanted to add other sheets to paste certain data, i.e. if i wanted code P1 to go into a new sheet what code would i need to enter in the current code and where?

    Thanks

    Mark

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

    Re: Pasting entire row to a new sheet if cell contains certain text

    Hi, Mark,

    Please Login or Register  to view this content.
    needs to be changed to
    Please Login or Register  to view this content.
    where new sheet should be changed to the proper name of the sheet.

    Ciao,
    Holger

  32. #32
    Registered User
    Join Date
    06-29-2014
    Location
    London
    MS-Off Ver
    2007
    Posts
    15

    Re: Pasting entire row to a new sheet if cell contains certain text

    I have altered that but for some reason now it is not picking up "O" and moving them to doors. any ideas
    Attached Files Attached Files

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

    Re: Pasting entire row to a new sheet if cell contains certain text

    Hi, Mark,

    and what shall I see in a workbook without data and without code?

    Ciao,
    Holger

+ 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. Newbie here
    By chevchelios in forum Hello..Introduce yourself
    Replies: 1
    Last Post: 11-20-2012, 02:08 AM
  2. Hello from a Newbie
    By JDC_8 in forum Hello..Introduce yourself
    Replies: 1
    Last Post: 11-18-2012, 08:05 PM
  3. Newbie Help. Is this possible?
    By taltos1 in forum Excel General
    Replies: 5
    Last Post: 11-12-2005, 12:40 PM
  4. [SOLVED] Help for newbie
    By Txl in forum Excel General
    Replies: 3
    Last Post: 10-11-2005, 01:05 AM
  5. Newbie with newbie question
    By elgrandekazoo in forum Excel - New Users/Basics
    Replies: 5
    Last Post: 03-28-2005, 02:13 PM

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