+ Reply to Thread
Results 1 to 24 of 24

Copy Different Cell Values Using VBA Code

  1. #1
    Forum Contributor
    Join Date
    12-30-2006
    Location
    Australia
    MS-Off Ver
    2017
    Posts
    151

    Copy Different Cell Values Using VBA Code

    Hi Experts,

    I've 2 separate worksheets: Sheet1 and Sheet2 as attached (filename: Sampe1.xls).

    Data entries are done mainly in Sheet2 with all the required fields, but there are only 3 values that I'm interested at.

    Those are: Request No, Requestor Name and Student Name.

    These 3 values in Sheet2 are to be transferred automatically to Sheet1 by a click of button.

    All input data in Sheet2 will be wiped out when it's already copied to Sheet1 with a click of button.

    All input data in Sheet2 will be copied to Sheet1 to the selected row (selected by user), so the selection is flexible.


    SAMPLE DATA:
    ==========
    Sheet2
    --------
    Request No: 1003
    Requestor Name: Elizabeth
    Student Name: Student 1, Student 2, Student 3, Student 4

    Sheet1
    --------
    1003 Elizabeth Student 1, Student 2, Student 3, Student 4


    Can this be done this way?

    Please help.

    Thank you.


    - Jack
    Attached Files Attached Files
    Last edited by SmallJack; 05-05-2015 at 11:33 AM. Reason: edit sample data for clarification
    Regards,
    Jack

  2. #2
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Copy Different Cell Values Using VBA Code

    maybe something like this
    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    12-30-2006
    Location
    Australia
    MS-Off Ver
    2017
    Posts
    151

    Re: Copy Different Cell Values Using VBA Code

    Hi nilem,

    Thanks for your reply and help.

    I've created a button in Sheet2 with your coding.

    Had tried it, but the output is different, see below.

    -> Values needed are from Sheet2 in cells: C5, C7, C9
    -> When I clicked the button, it copied these values to Sheet2 in different cells: B14, C14, D14.
    -> These values from Sheet2 should be copied to Sheet1 in cells: B6, C6, D6

    -> Also, how to clear Sheet2 cells: C3, C11?

    I've attached the updated file.

    Please help.

    Thanks.
    Attached Files Attached Files

  4. #4
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Copy Different Cell Values Using VBA Code

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    12-30-2006
    Location
    Australia
    MS-Off Ver
    2017
    Posts
    151

    Re: Copy Different Cell Values Using VBA Code

    Hi nilem,

    Thanks for your reply and help.

    It's much better now

    But, possible to allow a more flexible way to copy those values to Sheet1?

    For example:
    -> I want to copy these values from Sheet2 to Sheet1 in any empty cells within "Column B" only.
    -> Now cell B4 to B8 in Sheet1 already filled with some data, I want to copy the new values to B10 or B13 or other empty cell, depending on where I point my mouse pointer.
    -> If I point it to anywhere else outside "Column B", there will be a warning message as an indication.

    See attached file, Sampe3.xls

    Can it be done this way?

    Thanks for your help.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    05-06-2015
    Location
    ahmedabad,INDIA
    MS-Off Ver
    2007
    Posts
    1

    Re: Copy Different Cell Values Using VBA Code

    Hi Expert,

    i want to link sheet 2 (A1 cell) data to sheet 1 (C1 cell),
    so when i changing in sheet 2 (A1 cell) data automatically change in sheet 1 (C1 cell) data

  7. #7
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,058

    Re: Copy Different Cell Values Using VBA Code

    vishal9002 ,
    Unfortunately your post does not comply with Rule 2 of our Forum RULES. Do not post a question in the thread of another member -- start your own thread.

    If you feel an existing thread is particularly relevant to your need, provide a link to the other thread in your new thread.

    Old threads are often only monitored by the original participants. New threads not only open you up to all possible participants again, they typically get faster response, too.
    Never use Merged Cells in Excel

  8. #8
    Forum Contributor
    Join Date
    12-30-2006
    Location
    Australia
    MS-Off Ver
    2017
    Posts
    151

    Re: Copy Different Cell Values Using VBA Code

    Hi vishal9002,

    Appreciate if you don't hijack my post with your own questions.

    Thank you.

  9. #9
    Forum Contributor
    Join Date
    12-30-2006
    Location
    Australia
    MS-Off Ver
    2017
    Posts
    151

    Re: Copy Different Cell Values Using VBA Code

    Hi nilem,

    Are you able to help?

    Thank you.

  10. #10
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Copy Different Cell Values Using VBA Code

    Hi SmallJack,
    ok, try this
    Please Login or Register  to view this content.

  11. #11
    Forum Contributor
    Join Date
    12-30-2006
    Location
    Australia
    MS-Off Ver
    2017
    Posts
    151

    Re: Copy Different Cell Values Using VBA Code

    Hi nilem,

    Appreciate for your help.

    It's really great to see what those coding can do Thanks

    I've performed some testing on some cases and hit with 2 errors, see attached images.

    ERROR1 (image)
    -> On Sheet2, pressed the button, did not provide any cell values, clicked OK. Result: error message appear.

    ERROR2 (image)
    -> On Sheet2, pressed the button, went to Sheet1, did not provide any cell values, clicked OK. Result: error message appear.

    Will it be possible to provide some more friendlier messages than those error messages?

    Thanks.
    Attached Images Attached Images

  12. #12
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Copy Different Cell Values Using VBA Code

    try again
    Please Login or Register  to view this content.

  13. #13
    Forum Contributor
    Join Date
    12-30-2006
    Location
    Australia
    MS-Off Ver
    2017
    Posts
    151

    Re: Copy Different Cell Values Using VBA Code

    Hi nilem,

    Once again, appreciate for your kind help.

    It works almost perfect as expected

    I got 1 minor request, could you help to change below message?

    From:
    You have chosen [Sample5.xls]Sheet1!$B$11. Are you sure?

    To:
    You have chosen Sheet1 Cell B11. Are you sure?

    See attached image.

    Thank you.
    Attached Images Attached Images

  14. #14
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Copy Different Cell Values Using VBA Code

    replace this line
    Please Login or Register  to view this content.
    with this line
    Please Login or Register  to view this content.

  15. #15
    Forum Contributor
    Join Date
    12-30-2006
    Location
    Australia
    MS-Off Ver
    2017
    Posts
    151

    Re: Copy Different Cell Values Using VBA Code

    Hi nilem,

    Once again, appreciate for your kind help.

    I just spotted 1 issue, if I select 2 cells (B9, B10) together in Sheet1, the values will be copied to these cells together in row 9 and 10, see attached image.

    If I select either cell B9 or B10, it will copy to either cells only, not both cells together.

    Possible to restrict and prevent it?

    Thank you.
    Attached Images Attached Images

  16. #16
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Copy Different Cell Values Using VBA Code

    replace this line
    Please Login or Register  to view this content.
    with this line
    Please Login or Register  to view this content.

  17. #17
    Forum Contributor
    Join Date
    12-30-2006
    Location
    Australia
    MS-Off Ver
    2017
    Posts
    151

    Re: Copy Different Cell Values Using VBA Code

    Hi nilem,

    Many thanks and appreciate for your help and patience.

    All are working as expected now.

    I'll close this thread.

    Have a nice day

  18. #18
    Forum Contributor
    Join Date
    12-30-2006
    Location
    Australia
    MS-Off Ver
    2017
    Posts
    151

    Re: Copy Different Cell Values Using VBA Code

    Hi nilem,

    Just wondering if you could help out on below items:

    1) On sheet2, I've data on merge cells, can this data be copied out to the respective sheets?

    2) How to copy the data to differente worksheets, for example: Sheet3 and Sheet4?

    3) How to clear content using another button?

    Please refers to the attached file for sample data (Sample4.xls).

    Appreciate for your help.

    Thank you.
    Attached Files Attached Files

  19. #19
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Copy Different Cell Values Using VBA Code

    Hi SmallJack,
    try so
    Please Login or Register  to view this content.

  20. #20
    Forum Contributor
    Join Date
    12-30-2006
    Location
    Australia
    MS-Off Ver
    2017
    Posts
    151

    Re: Copy Different Cell Values Using VBA Code

    Hi nilem,

    Thanks for your help.

    Please see my comments below.

    Please Login or Register  to view this content.
    Could you help to modify the above coding to cater for below changes?

    1) On sheet2, I've data on merged cells, can this data be copied out to Sheet1, Sheet3 and Sheet4?

    For example:
    ---------------
    Sheet2
    -> Raw5 -> Cell C5, D5, E5 are merged cell (Yellow highlighted)
    -> Raw7 -> Cell C7, D7, E7 are merged cell (Yellow highlighted)
    -> Raw9 -> Cell C9, D9, E9 are merged cell (Yellow highlighted)

    See sample data as attached (Sampe5.xls)

    2) How to clear content using another button?

    Thank you for your help.
    Attached Files Attached Files

  21. #21
    Forum Contributor
    Join Date
    12-30-2006
    Location
    Australia
    MS-Off Ver
    2017
    Posts
    151

    Re: Copy Different Cell Values Using VBA Code

    Hi nilem,

    Sorry for the confustion.

    I've managed to modify the codes to cater for the changes.

    However, I'm a bit stuck with below code. How to use the same condition to cater for different worksheet?
    For example: Sheet3 and Sheet4?

    Please Login or Register  to view this content.
    Thank you.

  22. #22
    Forum Contributor
    Join Date
    12-30-2006
    Location
    Australia
    MS-Off Ver
    2017
    Posts
    151

    Re: Copy Different Cell Values Using VBA Code

    Hi nilem,

    How to clear the content for an individul cell?

    For example: clear content for cell C5, C7, C9

    I've tried below codes, but it's not working.
    Please Login or Register  to view this content.
    Appreciate if you could help.

    Thanks.

  23. #23
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Copy Different Cell Values Using VBA Code

    maybe so
    Please Login or Register  to view this content.
    about ClearContents
    if you have merged cells (eg C5:E5), then so
    Please Login or Register  to view this content.
    or
    Please Login or Register  to view this content.
    Last edited by nilem; 05-21-2015 at 12:09 AM.

  24. #24
    Forum Contributor
    Join Date
    12-30-2006
    Location
    Australia
    MS-Off Ver
    2017
    Posts
    151

    Re: Copy Different Cell Values Using VBA Code

    Hi nilem,

    Ok. Will try it out.

    Thanks for your help.
    Last edited by SmallJack; 05-25-2015 at 02:07 AM. Reason: Remove signature

+ 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. VBA Code to Move and/or Copy Sheets out to a New Workbook based on Cell Values
    By lhickerson in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-18-2014, 09:45 AM
  2. Excel/VBA code to copy cell that for either negative values or Red fonts
    By dkt081000 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-30-2014, 11:43 AM
  3. [SOLVED] VBA code to copy cell values to the next blank row in another sheet (all the same row)
    By rarias in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-11-2013, 03:08 AM
  4. [SOLVED] Automatically copy and paste (or update) cell values to another worksheet using VBA code
    By jjin in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 01-21-2013, 04:56 AM
  5. VBA code to copy from another workbook using multiple cell values
    By derryt in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-19-2012, 01:47 PM

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