+ Reply to Thread
Results 1 to 10 of 10

VBA copy and paste based on cell value

  1. #1
    Forum Contributor
    Join Date
    02-20-2014
    Location
    Ireland
    MS-Off Ver
    Excel 2013
    Posts
    108

    VBA copy and paste based on cell value

    Hi All,

    I have a list of employee names, beside each name is the shift they are working. i.e DS or NS (day shift or night shift)

    What I want to do is have a code look in the list and pull every row that has DS in it, and paste it into another sheet, but not to leave any spaces between rows as they are in the employee list.

    I hope this can be easily done. I'm ok with vba, getting better every day!

    Thanks in advance for any replies

  2. #2
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: VBA copy and paste based on cell value

    I assummed employee names were in column A and the shift was in column B:

    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    02-20-2014
    Location
    Ireland
    MS-Off Ver
    Excel 2013
    Posts
    108

    Re: VBA copy and paste based on cell value

    Hi, Thanks for the quick reply

    I have been working on a code

    Please Login or Register  to view this content.
    However this keeps returning an error saying "we can't paste because the copy and paste area is not the same size", I have made sure they are exact replicas in size.

    I realised I dont want to copy the whole row, jus column "B:G"

    Any Ideas?

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: VBA copy and paste based on cell value

    Change

    Please Login or Register  to view this content.
    INTO

    Please Login or Register  to view this content.

  5. #5
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: VBA copy and paste based on cell value

    I have made sure they are exact replicas in size.
    But the code doesn't know that. The code thinks you are taking the entire column B:G and trying to paste it to a non-entire column. It would work if you told it to paste to A1 but not A50 (for example).

    Probably would want to change to something more like this:

    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    02-20-2014
    Location
    Ireland
    MS-Off Ver
    Excel 2013
    Posts
    108

    Re: VBA copy and paste based on cell value

    Thanks for the reply.

    That works ok, but my code now seems to copy all cells, regardless of the "NS" or "DS" and is pasting them all into "DS Sheet", and relabelling them all as "DS"

    Here is my code as it is now

    Please Login or Register  to view this content.

  7. #7
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: VBA copy and paste based on cell value

    Please Login or Register  to view this content.
    Last edited by AB33; 09-09-2014 at 12:54 PM.

  8. #8
    Forum Contributor
    Join Date
    02-20-2014
    Location
    Ireland
    MS-Off Ver
    Excel 2013
    Posts
    108

    Re: VBA copy and paste based on cell value

    Apologies, my last reply was incorrect, Its just not pasting the "NS" Values to the "NS Sheet"

    Thanks for your code, but this too returns an error "Object not recognized".

    I have attached an example workbook so you can see whats happening.

    Thanks again for your time
    Attached Files Attached Files

  9. #9
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: VBA copy and paste based on cell value

    You are you looping back ward? The first cell to be copied would be the last row in sheet Histogram.
    Why are the other sheets layout look weird?

  10. #10
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: VBA copy and paste based on cell value

    You should remove these lines from the body of the code. If you do not, the code will keep copying on the same row again and again.

    Please Login or Register  to view this content.
    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. Copy and Paste based on a cell value
    By lzee61971 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-17-2014, 09:59 PM
  2. Copy-Paste based on cell value
    By Konexcelmath in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-30-2013, 03:32 AM
  3. [SOLVED] Copy/Paste Based on Value of Cell
    By l8tnite in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-25-2012, 06:17 PM
  4. Copy Paste based on Cell Value
    By Bwbisel in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-14-2011, 09:06 AM
  5. Copy and paste row based on cell value
    By contra76 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-20-2010, 03:23 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