+ Reply to Thread
Results 1 to 7 of 7

Copy Paste in another worksheet based on cell value vba

  1. #1
    Registered User
    Join Date
    02-26-2015
    Location
    Canada
    MS-Off Ver
    2010
    Posts
    4

    Copy Paste in another worksheet based on cell value vba

    Hi, I'm new with VBA but did quite a bit of macros last week with the help from this forum. Now I'm stuck with this one and can't figure it out. Any help is much appreciated.

    I have a schedule something like this on Sheet1:

    Name Mon Tue Wed
    John Surrey 0900-1700 Van 1230-1945 APH 0745-1515
    Sue Surrey 0715-1600 APH 0900-1700 APH 0900-1700
    Mike APH 0715-1600 APH 0900-1700 APH 0745-1515
    Dan APH 0900-1700 Surrey 0715-1600

    for each day of the week, shows the location and shift hours for each staff.
    On Sheet2 = "Monday" I have the required shifts for each location on Mondays. something like this. I have 7 worksheets for 7 days of the week.
    Mon Mon
    APH 0715-1600 Surrey 0715-1600
    APH 0900-1700 Surrey 0715-1600
    APH 0900-1700 Surrey 0900-1700
    APH 0745-1515 Surrey 0900-1700
    Surrey 0800-1730

    I need a macro to get the value of the first required shift for APH location (APH 0715-1600) and search in Sheet1 under Mon column, find the value, copy the corresponding staff name and paste it on Sheet "Monday" beside the first required shift on the left side cell. Then this repeats for the second required shift and so on. Then should go to the next location i.e. Surrey and starts with first required shift for Surrey (Surrey 0715-1600) and ...

    The result should be like:

    Mon Mon
    Mike APH 0715-1600 Sue Surrey 0715-1600
    Dan APH 0900-1700 Surrey 0715-1600
    APH 0900-1700 John Surrey 0900-1700
    APH 0745-1515 Surrey 0900-1700
    Surrey 0800-1730


    At the end I should know the required shifts that have no one assigned to and should be offered to staffs.

    On Sheet1, not all staffs have an assigned shifts (some cells are blank). The cells are color coded by location.
    On Sheet "Monday", there might be 2 or more of a same shift required.

    Let me know if I need to provide more info.

    Thanks in advance,

  2. #2
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: Copy Paste in another worksheet based on cell value vba

    Can you post an example workbook please, with before and after? As you can probably see, the formatting of your examples isn't great.

  3. #3
    Registered User
    Join Date
    02-26-2015
    Location
    Canada
    MS-Off Ver
    2010
    Posts
    4

    Re: Copy Paste in another worksheet based on cell value vba

    Thank you walruseggman!

    I have attached a sample worksheet. On tab "Monday" shows the before and after version. Your help is much appreciated.
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: Copy Paste in another worksheet based on cell value vba

    So really the only thing you need to change for this code to work is to change the days of the week on your "RN Schedule" worksheet to match the tab names (e.g. Mon -> Monday). Or you could change the tab names to match the schedule, just as long as they match. It's just easier to select the correct worksheet that way. If that's a deal breaker, let me know and I'll adjust the code.

    And it's important that your RN Schedule is positioned exactly as it is in your example, with the days of the week starting in C3 and the names starting in B4. If not, the code won't work correctly until we adjust it to tell it where the schedule is.

    Conversely, it doesn't matter how your schedules are formatted or positioned on the single-day worksheets. As long as it can find the shift name, it will put the person's name one cell to the left.

    Please Login or Register  to view this content.
    Last edited by walruseggman; 03-02-2015 at 10:08 AM.

  5. #5
    Registered User
    Join Date
    02-26-2015
    Location
    Canada
    MS-Off Ver
    2010
    Posts
    4

    Re: Copy Paste in another worksheet based on cell value vba

    This is incredible walruseggman I'm so amazed! Thank you so much.

    It worked great. there are just a couple of issues.
    1) can you please add a code at the beginning to remove all the names from worksheets "Monday", "Tuesday",..... like a clean start.
    2) if "RN Schedule" has blank, like D7 is blank, then the code doesn't work. it finds the first blank cell in worksheet "Tuesday" which is B2 and pastes Dan into it.
    3) if "RN Schedule" has more staff than needed scheduled for a shift, then the code doesn't work. it remains in an infinite loop. for example, on Wednesday, both John and Mike are scheduled for APH0745-1515 but on "Wednesday" tab we only have one shift of APH0745-1515 required. In this case it keeps going to "Loop Until Not c Is Nothing And c.Address <> FirstAdd" line. Is it possible to program it so after 10 tries, it paste a message like "You are overbooked for APH0745-1515 shift. Mike is also booked for APH0745-1515" at the bottom of the page.

  6. #6
    Registered User
    Join Date
    02-26-2015
    Location
    Canada
    MS-Off Ver
    2010
    Posts
    4

    Re: Copy Paste in another worksheet based on cell value vba

    Mr. walruseggman, please help me to get this code working. I'm having such a hard time finding solutions for those 3 issues. My deadline is coming up. I know it's a piece of cake for you. Please help me. I will thank you for ever.

  7. #7
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: Copy Paste in another worksheet based on cell value vba

    Try this. Please remember that the days of the week on the RN Schedule and the tab names need to be the same.

    Please Login or Register  to view this content.

+ 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: 2
    Last Post: 11-08-2011, 11:10 AM
  2. Copy Paste row from one worksheet to another based on DATE
    By niketmohan in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-21-2011, 08:29 AM
  3. Copy and Paste (Same worksheet) based on cell values
    By muckem333 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-02-2011, 04:43 PM
  4. Copy row based on date and then paste into a new worksheet based on section number
    By calmlaunch in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-25-2011, 11:40 PM
  5. copy rows based on cell value and paste to another worksheet
    By kingpeejay in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-29-2009, 01: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