+ Reply to Thread
Results 1 to 53 of 53

Copying row based off cell value to a sheet of the same name

  1. #1
    Forum Contributor
    Join Date
    10-26-2011
    Location
    Ottawa, ON Canada
    MS-Off Ver
    Excel 2011 for Mac
    Posts
    128

    Copying row based off cell value to a sheet of the same name

    Ok, very new to VBA/macros and all that...

    Here's my scenario...

    I have a document that has a sheet for each day of the week, Oct 1, Oct 2, Oct 3 example...

    If on sheet "Oct 1" column G:G has Oct 2 entered as the value, then that entire row will be copied to the 1st blank row of "Oct 2"... and so on for all sheets....

    I'v seen vbas that will copy row based off a value, but not to a sheet of the same name of the value being looked at..

    Any advise appreciated.

    Rob
    Last edited by hambly; 10-27-2011 at 06:22 PM.

  2. #2
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: Copying row based off cell value to a sheet of the same name

    Rob;
    Try this
    Please Login or Register  to view this content.
    Foxguy

    Remember to mark your questions [Solved] and rate the answer(s)
    Forum Rules are Here

  3. #3
    Forum Contributor
    Join Date
    10-26-2011
    Location
    Ottawa, ON Canada
    MS-Off Ver
    Excel 2011 for Mac
    Posts
    128

    Re: Copying row based off cell value to a sheet of the same name

    Thanks a lot FoxGuy... That was very helpful... I have no idea how it works, but it's getting there!

    Excuse my complete newness to VBA/Macro...

    So after I ran it, it did copy over some of the rows, but it would only copy over one row.

    Example if rows 3 and 4 contained "Mar13" it would copy over row 4 to sheet Mar13. If rows 5 and 6 contained Mar14 it would copy row 6 over to sheet Mar14. it missed/didn't copy the first entry. Testing this, it looks like it only copies the final entry. So if I had 4 entries of Mar14, it would only copy the last entry over.

    Would I also be able to have a popup window warning message if the entry was not a sheet name? It would need to ignore blanks.

    Thanks again for your help.
    Rob

  4. #4
    Forum Contributor
    Join Date
    10-26-2011
    Location
    Ottawa, ON Canada
    MS-Off Ver
    Excel 2011 for Mac
    Posts
    128

    Re: Copying row based off cell value to a sheet of the same name

    Now I think about it, it's probably just copying over onto the same row of the new sheet, so I just need to have it find the next blank row...

  5. #5
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: Copying row based off cell value to a sheet of the same name

    Quote Originally Posted by hambly View Post
    Now I think about it, it's probably just copying over onto the same row of the new sheet, so I just need to have it find the next blank row...
    I can't see any reason why it doesn't copy every row onto a new row on the worksheet. It is finding the next blank row for every entry in G:G. If it's missing an entry from G:G, I would assume that there%
    Last edited by foxguy; 10-27-2011 at 03:41 PM.

  6. #6
    Forum Contributor
    Join Date
    10-26-2011
    Location
    Ottawa, ON Canada
    MS-Off Ver
    Excel 2011 for Mac
    Posts
    128

    Re: Copying row based off cell value to a sheet of the same name

    Thanks for the reply.

    I have attached my test worksheet showing where I am right now. Sheet Mar12 has some entry to test...

    It could be me doing a very basic error... Today is my 1st day working in VBA...
    Attached Files Attached Files

  7. #7
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: Copying row based off cell value to a sheet of the same name

    Ok;
    Here's your file back.

    It was finding the next blank cell in column "A", not column "J", so it kept overwriting the same row.

    It was skipping a row on each sheet. If you want it to skip a row then change ".Offset(1)" back to ".Offset(2)".
    Attached Files Attached Files

  8. #8
    Forum Contributor
    Join Date
    10-26-2011
    Location
    Ottawa, ON Canada
    MS-Off Ver
    Excel 2011 for Mac
    Posts
    128

    Re: Copying row based off cell value to a sheet of the same name

    Amazing. Thanks again. Is there a way for it to not to copy over entries if they have already been copied over and you run the macro again?

  9. #9
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: Copying row based off cell value to a sheet of the same name

    It can skip rows that have already been copied in several ways.
    1) When a row is copied put a "True" in column "Z" then have the macro look in column "Z" for "True".
    2) Search the sheet copied to for a unique sequence. If Contractor # will only be used once per sheet, then search on sheets("Mar13") for "105", etc.
    In short there has to be a cell or combination of cells that will NEVER be duplicated under any situation, then the macro can search for that and skip the row if it is found.

    But # 1 is easier and could be faster if there are a lot of rows.

  10. #10
    Forum Contributor
    Join Date
    10-26-2011
    Location
    Ottawa, ON Canada
    MS-Off Ver
    Excel 2011 for Mac
    Posts
    128

    Re: Copying row based off cell value to a sheet of the same name

    Yes, I think the 1st option would be the easiest also.... What code would be the best for this?

    Also, if for some reason I wanted to cut/paste the row instead of copy/paste, what part of the code should I change?

  11. #11
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: Copying row based off cell value to a sheet of the same name

    Here's the file that marks a row as copied. Change the "AD" to whatever column you want.

    To change it from Copy to Cut requires more than a simple change. You have to start at the bottom of the column and work your way up. If you cut & paste row 3, row 4 moves up to become row 3, but the macro moves down a row to the new row 4. So the original row 4 gets skipped.
    It could also just cut and paste row 3 over & over again (because row 4 moves up to become row 3 after row 3 is cut).

    It's fairly easy, just different coding.

    I don't like cutting a row at the top of the sheet. Every time a macro cuts a row, Excel has to move everything up a row. If you have 60,000 rows of data, that might take quite a while. I personally would either manually delete rows (so I could manually verify that it got copied right), or have the macro delete all the copied rows at once at the end of the macro, so Excel only has to move all the rows up once.

    I also don't like deleting data at all. For some reason it always seems that 6 months from now I wish I still had a copy of all the deleted data. And there is always a small possibility that the macro "burps" and deletes the wrong row, especially if you keep adding more macros to do more things.
    Attached Files Attached Files

  12. #12
    Forum Contributor
    Join Date
    10-26-2011
    Location
    Ottawa, ON Canada
    MS-Off Ver
    Excel 2011 for Mac
    Posts
    128

    Re: Copying row based off cell value to a sheet of the same name

    Good advise. Thanks again for your your help... I'm sure I'll be back with new threads soon!

    Rob

  13. #13
    Forum Contributor
    Join Date
    10-26-2011
    Location
    Ottawa, ON Canada
    MS-Off Ver
    Excel 2011 for Mac
    Posts
    128

    Re: Copying row based off cell value to a sheet of the same name

    Just had a quick question - Could the VBA delete the J:J cells in the sheet that they have been copied to once I copy them over? Apart from the headings of course...

  14. #14
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: Copying row based off cell value to a sheet of the same name

    If you can do it manually, then VBA can do it (at least I can't think of any exceptions).

  15. #15
    Forum Contributor
    Join Date
    10-26-2011
    Location
    Ottawa, ON Canada
    MS-Off Ver
    Excel 2011 for Mac
    Posts
    128

    Re: Copying row based off cell value to a sheet of the same name

    Not sure if I should ask this question on this thread, since it's officially solved, but it is related...

    Playing with the vba I noticed that it will overwrite any rows that already have data in (manually entered). Would I be able to get the vba to look for the 1st blank row (after the headings)... I guess my question should be would you be able to alter the vba for this?

    Something else I was looking into was adding vlookup formulas on these sheets based off the contractor sheet. I have the vlookup working fine, but is it possible for the vba to keep the vlookup formula for rows it doesn't populate?

    I've attached an updated workbook to show what I'm trying to achieve... You'll notice the vlookup formulas on sheet Mar 13, looking at the data (entered manually) from 2012 contractors)

    I guess the formula won't be an issue as they'll still be intact at the end of the list after the data is copied over, so really all I need is for it to find the first blank row after row 2... I presume it should look at a different column than the ones with the formula already in place?

    Hope I'm making some sense?!
    Attached Files Attached Files

  16. #16
    Forum Contributor
    Join Date
    10-26-2011
    Location
    Ottawa, ON Canada
    MS-Off Ver
    Excel 2011 for Mac
    Posts
    128

    Re: Copying row based off cell value to a sheet of the same name

    Maybe vlookup won't be the best solution to auto populate based off the contractor number. I'm going to have a lot of sheets.. One for each day for a 3-4 month period... That's going to make it a pretty bloated worker book with all those formulas... Could a VBA be written instead of a vlookup?

  17. #17
    Forum Contributor
    Join Date
    10-26-2011
    Location
    Ottawa, ON Canada
    MS-Off Ver
    Excel 2011 for Mac
    Posts
    128

    Re: Copying row based off cell value to a sheet of the same name

    One thing I did notice is that all the vlookup formulas bloat the file size - The final file will have a sheet for each day of the month for a 3 month period... With only the formulas entered the file balloons to 8+mb...

  18. #18
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: Copying row based off cell value to a sheet of the same name

    Quote Originally Posted by hambly View Post
    Playing with the vba I noticed that it will overwrite any rows that already have data in (manually entered). Would I be able to get the vba to look for the 1st blank row (after the headings)... I guess my question should be would you be able to alter the vba for this?
    I don't understand, it already does that on my computer. It looks for the first blank cell in Column("I:I") and uses that row to copy into.

    Something else I was looking into was adding vlookup formulas on these sheets based off the contractor sheet. I have the vlookup working fine, but is it possible for the vba to keep the vlookup formula for rows it doesn't populate?
    Change the formula to
    Please Login or Register  to view this content.
    They will be overwritten when the macro runs, because the macro looks for blank cells in column "I"

    Could a VBA be written instead of a vlookup?
    Now I'm really lost. Maybe you should tell me what you are doing. I thought we already wrote a macro. What do you want to rewrite it for?

    One thing I did notice is that all the vlookup formulas bloat the file size - The final file will have a sheet for each day of the month for a 3 month period.
    You're right you will have a very bloated file. If you explain what you're trying to do (from beginning to end) we can help. Assume that you're teaching a brand new employee what you're doing and pretend that you don't have a computer. How would you do it on paper.

  19. #19
    Forum Contributor
    Join Date
    10-26-2011
    Location
    Ottawa, ON Canada
    MS-Off Ver
    Excel 2011 for Mac
    Posts
    128

    Re: Copying row based off cell value to a sheet of the same name

    Ho FoxGuy.. Thanks for sticking with me on this one!

    Ok, I see now that it looks for the first blank column on I:I I'll change that to another column as I will be empty if there are manual entries...

    Ok, so to describe what exactly it is I want to do...

    We have a strange business model where we can have 100 independent workers work for our company on any given day. At the end of the day they let us know when they want to work next. So on my worksheet for example Mar12 is a list of those who worked that day - At the end of the night each worker will let us know when they want to work again, and we enter that date in column I (and right now manually sort and paste to the new date sheet)
    So the VBA you wrote solves that.

    There is however a second way to get onto a work day - If a worker calls in we enter them manually into the day they want to work - This is where I wanted the VLookup to work. The manager can just enter the contractor number and all the other cells will be filled in from the info on the 2012 contractor list. (This list will never change)

    We also have the odd person who just shows up on a day, so we would use the same method, entering the contractor number and retrieving the rest of their info via VLOOKUP.

    As we have it now, it works well. The problem is when we have a worksheet for every day of the week for a 3 month period, and the VLOOKUP just gets too big....

  20. #20
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: Copying row based off cell value to a sheet of the same name

    I don't believe in copying data and also leaving it in the original place.
    I would always use formulas to display data that is stored on the contractor sheet.
    I still remember the first time a client swore up and down that a sheet would never change and 6 months later something did change. People change their names, they move, etc.
    (There may be occasional exceptions, but I can't think of any right now).

    I also don't believe in having 2 sheets with the same format that both display the data. I would leave all the data on 1 sheet and use filters to display the data the way I wanted it displayed. If I needed a sheet for display and a different for raw data, I would always use formulas to display the data and I can't think of any reason for having more than 1 sheet with the same format for display. I would just have 1 sheet and I would type in the date at the top (r use a pick list to pick a date) and the formulas on the sheet would then display everything I wanted.

    I do like to use a different sheet or form to do the actual data entry. The data entry sheet or form would have a "save" button to store it on the raw data sheet.

    But everyone has to do the things they're comfortable with. I generally code a little less efficiently than is necessary to get the job done. The difference in speed is not noticeable and it's easier for the next person who has to maintains the file. I always assume the next person doesn't know as much as I do.

    If my ideas sound like something you want to do, just let us know. There are plenty of people willing to help.

    ************************************

    What do you mean by
    the VLOOKUP just gets too big
    ? Does the formula get too long, or just too many, or what?
    Last edited by foxguy; 11-03-2011 at 06:32 PM.

  21. #21
    Forum Contributor
    Join Date
    10-26-2011
    Location
    Ottawa, ON Canada
    MS-Off Ver
    Excel 2011 for Mac
    Posts
    128

    Re: Copying row based off cell value to a sheet of the same name

    This project was something that was handed to me "as is" with a hope to simplify... I am open to any new methods.... I actually hate the fact that a new sheet is used for every day of the week... but I don't know how to tackle that issue ...

  22. #22
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: Copying row based off cell value to a sheet of the same name

    Why do you need a separate sheet for each day?

    On the raw data sheet you can filter by any column. If you use "AutoFilter" it creates a filter for ever column. Just pick the column you want in the top cell and select what filter you want. If you don't like it just turn it off. Easy as pie.

    You should use formulas like you were doing on Mar 13 for every column that needs data from the contractors sheet. Lock the cells and protect the sheet so that they can't be edited. Unlock ONLY the cells that need to be manually edited.

    Try those and see if makes things easier.

  23. #23
    Forum Contributor
    Join Date
    10-26-2011
    Location
    Ottawa, ON Canada
    MS-Off Ver
    Excel 2011 for Mac
    Posts
    128

    Re: Copying row based off cell value to a sheet of the same name

    Hi FoxGuy.. Thanks for the tip... I'm working on a 'one sheet' only example, using filters as you suggested... Will see if they like it...

    One thing I would still like to do is use the VBA you wrote to move rows to different sheets based off the cell data.. So if they write QUIT I'd still like it to copy over the row (but only from A:M) to the QUIT sheet... The difference is it will only be looking for certain words and ignoring the dates, and won't be copying the entire row..

    Could you point me in the right direction on what to change in your VBA?

  24. #24
    Forum Contributor
    Join Date
    10-26-2011
    Location
    Ottawa, ON Canada
    MS-Off Ver
    Excel 2011 for Mac
    Posts
    128

    Re: Copying row based off cell value to a sheet of the same name

    Hi FoxGuy... I wonder if you could alter the code that you kindly provided for me (see below)

    Please Login or Register  to view this content.
    I'd like to change it so instead of copying the entire row, it only copies columns A:L

    You had also mentioned that it was looking at column I and if it's empty it copies onto that row... Could you change it to look at column A instead?

    Thanks again
    Rob

  25. #25
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: Copying row based off cell value to a sheet of the same name

    I'm doing this on the fly without testing it, so back up before running it.

    '***************************************
    In the future change the values between these lines to change ranges.
    '***************************************

    '--------------------------------------------------------
    I changed the code between these lines so you can see what was changed.
    (In case something goes wrong).
    '--------------------------------------------------------

    Please Login or Register  to view this content.

  26. #26
    Forum Contributor
    Join Date
    10-26-2011
    Location
    Ottawa, ON Canada
    MS-Off Ver
    Excel 2011 for Mac
    Posts
    128

    Re: Copying row based off cell value to a sheet of the same name

    Great. Thanks. I will test this out and let you know how it works...

    One (final) thing that has been requested is that if the cell in row "I" is blank it also returns an error message. So it would need to look to see if the row has data and return the error if I is blank.

    hanks again for all your help... I'm not sure what the protocol is on the forum and if I'm overstepping my request for assistance...

  27. #27
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: Copying row based off cell value to a sheet of the same name

    If you're asking a new question that is completely unrelated to the original question, you should start a new thread.
    Most beginners don't realize what everything that is needed to answer completely, so as long as you're just refining the original question it's ok to continue with the original thread.

    You probably shouldn't mark the thread "Solved" until you're completely satisfied. You were lucky that I noticed that you added something to a "Solved" thread. I usually quit looking at threads that are marked "Solved". I just hadn't gotten around to unsubscribing to your thread yet, so it popped to the top of my subscribed threads.

    If you do need to refine a "Solved" thread, it's probably a good idea to send a Private Message to me to let me know that you have added something. Be sure and put a link to the thread in the PM so I can find the thread.

    '***************************************
    In the future change the values between these lines to change ranges.
    '***************************************

    '--------------------------------------------------------
    I changed the code between these lines so you can see what was changed.
    (In case something goes wrong).
    '--------------------------------------------------------

    Please Login or Register  to view this content.

  28. #28
    Forum Contributor
    Join Date
    10-26-2011
    Location
    Ottawa, ON Canada
    MS-Off Ver
    Excel 2011 for Mac
    Posts
    128

    Re: Copying row based off cell value to a sheet of the same name

    Thanks for the advise.... Makes sense... Yes, I was probably to early on the 'solved' trigger... and didn't felt like PM'ing would have been the incorrect thing to do...

    I'll take a look at the code over the next day or so and let you know how it goes...

    Cheers
    Rob

  29. #29
    Forum Contributor
    Join Date
    10-26-2011
    Location
    Ottawa, ON Canada
    MS-Off Ver
    Excel 2011 for Mac
    Posts
    128

    Re: Copying row based off cell value to a sheet of the same name

    Hi FoxGuy. As mentioned in the PM, I've attached the latest document which gives the error message.
    Attached Files Attached Files

  30. #30
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: Copying row based off cell value to a sheet of the same name

    Boy, I really messed up that sub(). I'm embarrassed to claim it as mine.

    I tested this file, and it's working right (I think).
    One thing:
    You asked that it check column A on the next sheet to find the next empty row. Since there is no data in Column A "Shuttle" it kept finding row 3 and replaced the previous data. I changed it so that it checks Column J (that made the most sense to me, since there had to be a value in Column J in order to know what sheet to copy to.

    You can change it to whatever you want by changing the values between the '****************************
    Attached Files Attached Files

  31. #31
    Forum Contributor
    Join Date
    10-26-2011
    Location
    Ottawa, ON Canada
    MS-Off Ver
    Excel 2011 for Mac
    Posts
    128

    Re: Copying row based off cell value to a sheet of the same name

    Thanks.

    Yes. I added column A just recently. Can you have it check column D instead? There's a chance J will be empty at some point. The last name will always be complete...

    Ok just read where I can change it.. Thanks! Ok, let me take a look. The reason I didn't want it to be J was because we'll be adding manual entries as well, which won't necessarily have a next work day.

    If you have time, would you be able to add notes to a copy of the VBA for what each section means? I'd really like to learn and understand what it all means.. Right now it is (mostly) very Greek to me...

    Thanks again for your fast responses...

    FYI, I did show them the Filter method... and it seemed way easier.. They just don't want to take that leap right now.... Maybe next year! It makes way more sense though, although they do use the historical data of the daily sheets... That was the only thing the filter method didn't have.

  32. #32
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: Copying row based off cell value to a sheet of the same name

    I have some suggestions 2 make your workbook more automatic and less prone to typos.

    1) Create a PickList and put validation in the "Next Booking Day" column. That way the user won't be able to accidentally type "Mar 30" instead of "Mar30". The picklist could be designed to automatically update itself and add new sheets to the workbook with the correct name.

    2) Name the cells in each worksheet that identify which columns to use in the macro (just make sure each name is scoped to the sheet not the workbook, so each sheet can have it's own set of names the same as all the other sheets). This would allow you to add, delete, rearrange columns, etc. without having to change the macro. (This would require # 3 also).

    3) Have the macro copy the sheet format to the next sheet and add the names for that sheet, etc. So if you rearrange the current sheet the macro would automatically rearrange the new sheet's columns. This could be a problem if you copy data to Mar30 from Mar27, then rearrange the data on Mar28 and copy data to Mar30 a 2nd time, but it can be figured out.

  33. #33
    Forum Contributor
    Join Date
    10-26-2011
    Location
    Ottawa, ON Canada
    MS-Off Ver
    Excel 2011 for Mac
    Posts
    128

    Re: Copying row based off cell value to a sheet of the same name

    Thanks for the suggestions. I had thought about the drop down, but thought it might be tricky just because of the amount of dates (around 3 months) would make the list lengthy.... Though your suggestion of it automatically updating and creating new sheets is intriguing...

  34. #34
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: Copying row based off cell value to a sheet of the same name

    Here's all the notes I think are relevant.

    I did improve it a bit. I forgot about turning Events back on if an error occurs. Don't want to leave your workbook not working. Also rearranged things just to make it a bit more efficient.

    I have deliberately used techniques that are easier to understand for beginners. Some of these things could be more effiecient but harder to understand.
    Attached Files Attached Files

  35. #35
    Forum Contributor
    Join Date
    10-26-2011
    Location
    Ottawa, ON Canada
    MS-Off Ver
    Excel 2011 for Mac
    Posts
    128

    Re: Copying row based off cell value to a sheet of the same name

    Ok, I just realized I don't need the drop down to show for validation.. That's what I'll do there then , so a warning pops up if they enter an incorrect date format. SHould I start a new thread if I want more info on how to have a list update itself and add new sheets?

  36. #36
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: Copying row based off cell value to a sheet of the same name

    Yes you should start another thread.

  37. #37
    Forum Contributor
    Join Date
    10-26-2011
    Location
    Ottawa, ON Canada
    MS-Off Ver
    Excel 2011 for Mac
    Posts
    128

    Re: Copying row based off cell value to a sheet of the same name

    Hi FoxGuy - The latest one you sent me (with notes) worked fine the first time (running from the 2012 contractor) page, but when I tried it from the next page, (Mar11) I got J is blank errors for cells at the end of the list... Even if column D was empty.

  38. #38
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: Copying row based off cell value to a sheet of the same name

    Sorry, I forgot that I changed it to use .UsedRange. It didn't matter as long as you had never used cells below the data, so I never caught it.

    Make this change:

    Please Login or Register  to view this content.

  39. #39
    Forum Contributor
    Join Date
    10-26-2011
    Location
    Ottawa, ON Canada
    MS-Off Ver
    Excel 2011 for Mac
    Posts
    128

    Re: Copying row based off cell value to a sheet of the same name

    Thanks, though I a, lost as to where exactly the new section code should go?

  40. #40
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: Copying row based off cell value to a sheet of the same name

    Put this in with the rest of the "Dim"s
    Please Login or Register  to view this content.
    Replace This Line
    Please Login or Register  to view this content.
    with these lines
    Please Login or Register  to view this content.

  41. #41
    Forum Contributor
    Join Date
    10-26-2011
    Location
    Ottawa, ON Canada
    MS-Off Ver
    Excel 2011 for Mac
    Posts
    128

    Re: Copying row based off cell value to a sheet of the same name

    Thanks again. I've added the code in. I am now receiving an "Error 13 - Type Mismatch"

    Not sure if it's due to some changes I've been making.. I've added validation for J.. Other than that, I don't think I changed anything else...

    See attached
    Attached Files Attached Files

  42. #42
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: Copying row based off cell value to a sheet of the same name

    My bad;

    Change This line:
    Please Login or Register  to view this content.

  43. #43
    Forum Contributor
    Join Date
    10-26-2011
    Location
    Ottawa, ON Canada
    MS-Off Ver
    Excel 2011 for Mac
    Posts
    128

    Re: Copying row based off cell value to a sheet of the same name

    "My bad" That's music to my ears - I always expect it to be something easy that messed up...
    Great. Seemed to do the trick. Thanks!

  44. #44
    Forum Contributor
    Join Date
    10-26-2011
    Location
    Ottawa, ON Canada
    MS-Off Ver
    Excel 2011 for Mac
    Posts
    128

    Re: Copying row based off cell value to a sheet of the same name

    Hi FoxGuy... Everything is working pretty good as of now...

    One update I would like is if the Data in the Next Day Booking column is already the same as the sheet it is already in, and it is yet to have a TRUE value, then nothing will happen. Right now it duplicates the entries at the bottom of the list...

  45. #45
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: Copying row based off cell value to a sheet of the same name

    I'm curious;
    How did the data get into the new sheet, but it didn't get marked TRUE in the current sheet?

    This would require trying to find the name in the new sheet and checking all the values in the current row to the row in the new sheet and ignore some changes (like the date and True, etc).
    That actually should be a sub of it's own and my sub should call the new sub to find and check the new data. I believe that it would be a lot more complicated
    You already have a sub that will probably get more complicated as time goes by. You need to understand this one first.
    I don't want to create something than has too much possibility of screwing things up.

  46. #46
    Forum Contributor
    Join Date
    10-26-2011
    Location
    Ottawa, ON Canada
    MS-Off Ver
    Excel 2011 for Mac
    Posts
    128

    Re: Copying row based off cell value to a sheet of the same name

    An example would be if you run the VBA for Mar12... rows are copied into Mar13. Entries in Mar13 now don't have 'True' marked. If you now run the VBA on Mar13 and some entries still have Mar13 they will be added to the bottom of the list.

    This is more of an issue for the sheets that are not dates. The "WDR" sheet for example. This sheet will have the VBA ran quite often, but maybe only one or two rows will be updated with dates. The rest will stay in the WDR sheet. So now their will be one entry that is marked as 'True' and one that isn't...

    Their could be another way around this that I'm not thinking of...

  47. #47
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: Copying row based off cell value to a sheet of the same name

    All right I didn't understand.

    This should be easy for you to figure out.
    When the sheet locates which sheet to copy to:
    Just put in a check "If shFrom is shTo Then".
    Give it a try to figure out where to put it and what you want to happen when it's true or false.

  48. #48
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: Copying row based off cell value to a sheet of the same name

    Just thought I would point out something.

    If the column with the Dates/Sheets in it was not being copied you would not have this problem.
    This demonstrates one way that you may want to rearrange the sheet, which is an argument for naming the cells/columns so the macro would still work if you move the column out of the copy range.

    Another solution would be to use a different column outside the copy range (say "Z") and put an equation in the current Date/Sheet column "=$Z1". Then the date doesn't gets copied but you don't have to move the current column outside the copy range.

  49. #49
    Forum Contributor
    Join Date
    10-26-2011
    Location
    Ottawa, ON Canada
    MS-Off Ver
    Excel 2011 for Mac
    Posts
    128

    Re: Copying row based off cell value to a sheet of the same name

    Interesting. I'd like to keep the date column where it is as the staff use tiny netbooks and scrolling is a pain.... Also if the data is not copied over, now they'll now have to fill in all the rows again or get a bunch of error messages for the blanks...

    "I'm stuck on your homework assignment!

    Just put in a check "If shFrom is shTo Then".
    Give it a try to figure out where to put it and what you want to happen when it's true or false."

    I know that if it's True then I don't want it to copy but to keep checking and if false then to perform the copy... May I can just tell Siri to do it!

  50. #50
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: Copying row based off cell value to a sheet of the same name

    I'm honestly not trying to be a pain.
    Over the years I have seen patterns of behavior. People get help and don't try to understand what was done. Then later on they want a simple change and they have no idea how to make the change. And people who can help don't want to spend all the time trying to figure out what I've done in order to help.

    I'm trying to help people do stuff on their own and only help when they get stuck. Unfortunately I enjoy coding so much I always seem to forget that I'm trying to help, not do the work for them.

    You have a situation that you will want to expand in the future. It is not the best design and the current solution will not easily lend itself to modification. It's too late for me to help you design the macro yourself. I can only try and encourage you to try and figure out how the macro works so that you might modify it in the future by yourself.

    Or you can take the easy way and just delete all the Dates from the new sheet, or change the Date to something that won't get copied (Like Mar 30 instead Mar30) so the macro skips over the row when the date doesn't have a matching sheet.

  51. #51
    Forum Contributor
    Join Date
    10-26-2011
    Location
    Ottawa, ON Canada
    MS-Off Ver
    Excel 2011 for Mac
    Posts
    128

    Re: Copying row based off cell value to a sheet of the same name

    Thanks FoxGuy. I totally understand. I have been uncomfortable asking so many questions along the way... It's just VBA is totally new to me, as in the day you sent me the code I had to Google where it went...

    I will try and get back on the bike.. Even though I don't know how to ride the bike so far...

    Thanks for all your assistance - You've been extremely helpful.

  52. #52
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: Copying row based off cell value to a sheet of the same name

    My bad. For some reason, I got the impression that you were familiar with coding and just being lazy.

    Change this code:

    Please Login or Register  to view this content.
    I do believe that you will want to add/change this in the future, so I advise you to start learning. I believe this macro will start causing you headaches eventually or the users will start complaining when they want the workbook improved.

  53. #53
    Forum Contributor
    Join Date
    10-26-2011
    Location
    Ottawa, ON Canada
    MS-Off Ver
    Excel 2011 for Mac
    Posts
    128

    Re: Copying row based off cell value to a sheet of the same name

    Much appreciated. No, I definitely want to learn it, which is why I requested notes... Time constraints being what they are, I don't have long to get this ready... In fact I have a meeting tomorrow to show this...

    What I have now is far above and beyond what they used before - And I have you to thank for that... I will certainly start learning it more...

    Thanks again...

+ 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