+ Reply to Thread
Results 1 to 20 of 20

If Cell = X Copy Entire row to another sheet

  1. #1
    Registered User
    Join Date
    08-03-2012
    Location
    Manchester
    MS-Off Ver
    Excel 2010
    Posts
    24

    If Cell = X Copy Entire row to another sheet

    Hi, I looked at few threads similar to this, but I couldn't find what I was looking for. So I need some help writing a macro.

    In my spreadsheet I need to find the following:- In the Data Sheet, if the word "Apple" is detected I want the entire row to be copied to the Apples Sheet. In the same macro if the word "Orange" is detected the entire row should be copied to the Oranges Sheet. The same if "Pears" is detected the entire row should be copied to the Pears Sheet

    The headings don't need to be copied as they are already in place.

    I hope someone can help me and I apologies if I overlooked something similar to this.

    Thanks in advance!

    Example.xlsx

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

    Re: If Cell = X Copy Entire row to another sheet

    if you can have sheets names = fruit names
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    08-03-2012
    Location
    Manchester
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: If Cell = X Copy Entire row to another sheet

    Cheers mate that worked. But I made some slight changes to the spreadsheet and I can't get it too work now. Within the macro where i put the sheet name it doesn't let me put 2 words i.e. Apples Cake
    Last edited by Misbah211; 08-05-2012 at 09:59 AM.

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

    Re: If Cell = X Copy Entire row to another sheet

    if you can have sheets names = fruit names, check Pears cake

  5. #5
    Registered User
    Join Date
    08-03-2012
    Location
    Manchester
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: If Cell = X Copy Entire row to another sheet

    I did that but I get an error. Don't know what I'm doing wrong.

  6. #6
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520
    You have pear cake in main sheet and the sheet name is pear cakes with an s. So its not finding the sheet.
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

  7. #7
    Registered User
    Join Date
    08-03-2012
    Location
    Manchester
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: If Cell = X Copy Entire row to another sheet

    Yeah I fixed that, but I still get an error. For some reason I can't enter 2 words where I put the name of the sheet i.e. Apples Cake

    Example.xlsm

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

    Re: If Cell = X Copy Entire row to another sheet

    Please Login or Register  to view this content.
    variable without space

  9. #9
    Registered User
    Join Date
    08-03-2012
    Location
    Manchester
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: If Cell = X Copy Entire row to another sheet

    Ah Cheers, I got that example working now. But I'm having trouble trying to manipulate it for my database, as I'm not good at coding. I've attached an example with the exact fields. If you could help me out I'd be great full.

    Example with copy of fields.xlsx

  10. #10
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: If Cell = X Copy Entire row to another sheet

    This will work. You need to save the workbook as xlsm or xlsb to save code in the workbook

    Please Login or Register  to view this content.

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

    Re: If Cell = X Copy Entire row to another sheet

    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    08-03-2012
    Location
    Manchester
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: If Cell = X Copy Entire row to another sheet

    Cheers again, that works fine, but If I try to have more sheets and use the macro it says "Subscript out of Range" How can I adjust this? This is an updated spreadsheet.


    Example with copy of fields.xlsm

  13. #13
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: If Cell = X Copy Entire row to another sheet

    The names of the data and tabs(sheetsname) has to be the same.

    See Yougurt (Yogurt)
    See Crips (Crisps)
    Notice my main language is not English.

    I appreciate it, if you reply on my solution.

    If you are satisfied with the solution, please mark the question solved.

    You can add reputation by clicking on the star * add reputation.

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

    Re: If Cell = X Copy Entire row to another sheet

    be more heedful
    if you can have sheets names = fruit names, check crips

  15. #15
    Registered User
    Join Date
    08-03-2012
    Location
    Manchester
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: If Cell = X Copy Entire row to another sheet

    Sorry, my bad oeldere, I was making it in a rush and I didn't check the spelling

  16. #16
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: If Cell = X Copy Entire row to another sheet

    In the topic below you find in #7 a code to name your sheets.

    http://www.excelforum.com/excel-prog...ming-tabs.html

  17. #17
    Registered User
    Join Date
    08-03-2012
    Location
    Manchester
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: If Cell = X Copy Entire row to another sheet

    Thanks for the help guys. But I've come across another problem when I tried replicating it in my actual database. When I run the macro it copies the data to row D29 and not D10. Also when copying from the Data feed sheet, I want to exclude Column P (Visibility) as I don't want to copy that to the other sheets.

    Hope that makes sense.

    Example - Copt of fields.xlsm
    Last edited by Misbah211; 08-05-2012 at 03:06 PM.

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

    Re: If Cell = X Copy Entire row to another sheet

    only one table in each sheet, otherwise the line
    lastrow = Sheets(sheetname).Cells(Rows.Count, "D").End(xlUp).Row
    find the last used row of second table
    Last edited by patel45; 08-06-2012 at 02:28 AM.

  19. #19
    Registered User
    Join Date
    08-03-2012
    Location
    Manchester
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: If Cell = X Copy Entire row to another sheet

    Ok I see, I suppose I can change the tables around so it works. What about if I want to exclude Column P (Visibility) as I don't want to copy that to the other sheets, is there a way of doing that within the same macro?

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

    Re: If Cell = X Copy Entire row to another sheet

    it's very easy if you put this column as last column, so you can change
    Range(Cells(arow, 4), Cells(arow, 16)).Copy Sheets(Apple).Cells(lastrow + 1, 4)
    in
    Range(Cells(arow, 4), Cells(arow, 15)).Copy Sheets(Apple).Cells(lastrow + 1, 4)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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