+ Reply to Thread
Results 1 to 23 of 23

Copy specific cells in a row from one workbook to another based on Cell value

  1. #1
    Registered User
    Join Date
    05-10-2017
    Location
    BANGALORE
    MS-Off Ver
    2016
    Posts
    21

    Red face Copy specific cells in a row from one workbook to another based on Cell value

    Hi All

    I am new to VBA coding and in urgent need of a code that can copy few cells in a row from one workbook to another based on cell value.

    To explain my requirement further I have a workbook named "temp" with one primary cell value which when changed to "Accepted" only specific cells (including "Accepted") should copy to another workbook named "perm". Upon pasting the row in "perm", at the beginning i.e. in the first column, a name lets say "Robert" should also be placed in.

    Any help at this coding will be much appreciated.

    Regards,
    prvnchdry

  2. #2
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,210

    Re: Copy specific cells in a row from one workbook to another based on Cell value

    Hi prvnchdry

    Welcome to the forum....
    Is it two different workbooks named [TEMP] and [PERM] or two different worksheets
    If Workbooks, what are the sheet names within that we must copy from and copy to.
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  3. #3
    Registered User
    Join Date
    05-10-2017
    Location
    BANGALORE
    MS-Off Ver
    2016
    Posts
    21

    Re: Copy specific cells in a row from one workbook to another based on Cell value

    Thank you for the reply.

    Its two different workbooks. The sheet name in TERM is "old" and PERM is "new". Thanks for probing.

  4. #4
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,210

    Re: Copy specific cells in a row from one workbook to another based on Cell value

    This code will give you an idea, however you need to give more information i.e.
    In what column do we find the criteria "Accepted"
    Must the entire row be copied or only certain columns
    Where must it be pasted to on the new sheet etc etc etc

    Or just upload a sample workbook depicting a before and after scenario where the workbook names are just sheet 1 and sheet2 names

    Please Login or Register  to view this content.
    Last edited by sintek; 05-11-2017 at 12:06 PM.

  5. #5
    Registered User
    Join Date
    05-10-2017
    Location
    BANGALORE
    MS-Off Ver
    2016
    Posts
    21

    Re: Copy specific cells in a row from one workbook to another based on Cell value

    I have attached here both the sheets now.

    In the "temp" sheet only the cells of my interest are visible. Upon choosing "Accepted" from the drop down in column AG, the row should copy and paste from Column B onwards in workbook "Perm".
    And once this is pasted, the "name" should populate in the first column as depicted.

    Thank you.
    Attached Files Attached Files
    Last edited by prvnchdry; 05-11-2017 at 11:55 AM.

  6. #6
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,210

    Re: Copy specific cells in a row from one workbook to another based on Cell value

    Right the amended code in Post 4 has been tested and works. Just one thing where can the code go and find the name to put in column A on sheets("New") Can't always be you I'm sure.

  7. #7
    Registered User
    Join Date
    05-10-2017
    Location
    BANGALORE
    MS-Off Ver
    2016
    Posts
    21

    Re: Copy specific cells in a row from one workbook to another based on Cell value

    Thanks a ton. Works like a charm. Exactly what I was looking for.

    But one last thing, the whole row is getting copied to the "Perm" workbook. Since it has defined headers its important only the unhidden cells from "Temp" go and sit in this book.

    And to your question, yes the name isnt always mine. I am planning to tweak in here and handover to other individuals so that we all have these rows placed in Perm book on a sharepoint folder.

  8. #8
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,210

    Re: Copy specific cells in a row from one workbook to another based on Cell value

    Which columns do you want to copy over and does the Temp sheet not contain the name that must go into Col A anywhere.

    EDITED:

    This solves the column issue....
    Please Login or Register  to view this content.
    Still would like to incorporate code to take the name from somewhere...Any ideas cause currently this is the code being used
    Please Login or Register  to view this content.
    Last edited by sintek; 05-11-2017 at 01:57 PM. Reason: EDITED: Put code in CommandButton

  9. #9
    Registered User
    Join Date
    05-10-2017
    Location
    BANGALORE
    MS-Off Ver
    2016
    Posts
    21

    Re: Copy specific cells in a row from one workbook to another based on Cell value

    I want columns B, C, F, G, I, V, X, AG only to be copied. Yes the temp sheet doesnt have the Writer name in it and needs to be added in Perm once these specific columns gets copied.

    Also if there are multiple rows in the temp sheet - all accepted, can this code help copying all these rows in one go?
    Last edited by prvnchdry; 05-11-2017 at 01:39 PM. Reason: just noticed this isnt working

  10. #10
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,210

    Re: Copy specific cells in a row from one workbook to another based on Cell value

    Yes the temp sheet doesnt have the Writer name in it
    What column contains this name
    can this code help copying all these rows in one go?
    Yes the code has been tested an copies all with "Accepted"

  11. #11
    Registered User
    Join Date
    05-10-2017
    Location
    BANGALORE
    MS-Off Ver
    2016
    Posts
    21

    Re: Copy specific cells in a row from one workbook to another based on Cell value

    Yesss the specified columns are copied. (y) But now there is one last thing troubling me, the code when run just copies the last row and not all the rows with accepted option.

  12. #12
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,210

    Re: Copy specific cells in a row from one workbook to another based on Cell value

    See amended code in post 8

  13. #13
    Registered User
    Join Date
    05-10-2017
    Location
    BANGALORE
    MS-Off Ver
    2016
    Posts
    21

    Re: Copy specific cells in a row from one workbook to another based on Cell value

    Sorry missed to reply this....well can a range be validated with some names in it e.g prvnchdry, robert, dave, andrew?

  14. #14
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,210

    Re: Copy specific cells in a row from one workbook to another based on Cell value

    What column in the Temp book would you like the Data Validation that the user chooses name

  15. #15
    Registered User
    Join Date
    05-10-2017
    Location
    BANGALORE
    MS-Off Ver
    2016
    Posts
    21

    Re: Copy specific cells in a row from one workbook to another based on Cell value

    Column AH should do.

  16. #16
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,210

    Re: Copy specific cells in a row from one workbook to another based on Cell value

    K see updated code and Data validation in new worksheet...Think this one is solved....you agree.
    Attached Files Attached Files

  17. #17
    Registered User
    Join Date
    05-10-2017
    Location
    BANGALORE
    MS-Off Ver
    2016
    Posts
    21

    Re: Copy specific cells in a row from one workbook to another based on Cell value

    Thanks a ton friend! You exceeded my expectation with the last code of data validation...kudos (y)

  18. #18
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,210

    Re: Copy specific cells in a row from one workbook to another based on Cell value

    It's a pleasure...Glad I could help. Thanks for the rep point.

  19. #19
    Registered User
    Join Date
    05-10-2017
    Location
    BANGALORE
    MS-Off Ver
    2016
    Posts
    21

    Re: Copy specific cells in a row from one workbook to another based on Cell value

    Hi again, the code has been highly appreciated in my team today. We have eliminated the manual efforts of copy pasting that consumed our daily work routine by 30%. So many thanks!

    Also I have received one suggestion if there is a way to color code the names, either after pasting in Col A or before copying the cells - with the color predefined using conditional formatting. So a green fill for robert, red for dave, orange for prvnchdry and so on. This would help us differentiate in a single glance.

    Thank you for looking into this.

  20. #20
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,210

    Re: Copy specific cells in a row from one workbook to another based on Cell value

    Have a look at attached sample file. I put conditional formatting in Column A as per image
    ColourFormatting.png
    Attached Files Attached Files

  21. #21
    Registered User
    Join Date
    05-10-2017
    Location
    BANGALORE
    MS-Off Ver
    2016
    Posts
    21

    Re: Copy specific cells in a row from one workbook to another based on Cell value

    I am sorry but is there a code within the perm book? I cant see it
    Last edited by prvnchdry; 05-12-2017 at 03:34 AM. Reason: Its working!

  22. #22
    Registered User
    Join Date
    05-10-2017
    Location
    BANGALORE
    MS-Off Ver
    2016
    Posts
    21

    Re: Copy specific cells in a row from one workbook to another based on Cell value

    Quote Originally Posted by prvnchdry View Post
    I am sorry but is there a code within the perm book? I cant see it
    No worries I figured this out and its an excellent idea. Thank you very much.

  23. #23
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,210

    Re: Copy specific cells in a row from one workbook to another based on Cell value

    Glad you got it working

+ 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. [SOLVED] VBA code to copy specific cells based on cell value
    By Dineth in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-10-2016, 12:47 PM
  2. [SOLVED] Copy filename of source workbook to specific cell in specific tab in destination workbook.
    By MagicMan in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-28-2015, 10:29 PM
  3. [SOLVED] Macro to copy specific data from one WB to specific cells in another WB based on specific
    By d_rose in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-26-2014, 11:05 AM
  4. Copy 2 cells from each Row (into another Workbook) Based on Criteria of a third cell?
    By pharmerjoe7 in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 12-07-2013, 12:39 PM
  5. [SOLVED] Copy specific cell in various workbooks to another workbook, but in consequtive cells
    By andreroux in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 06-06-2013, 10:49 AM
  6. [SOLVED] Copy specific cells based on one word in the cell, to a different worksheet
    By Lfaulst1 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-30-2013, 05:26 PM
  7. Replies: 6
    Last Post: 02-03-2012, 06:03 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