+ Reply to Thread
Results 1 to 19 of 19

Copy cells via VBA

  1. #1
    Forum Contributor
    Join Date
    09-10-2010
    Location
    europe
    MS-Off Ver
    Excel 2007
    Posts
    149

    Question Copy cells via VBA

    When I selecting the third row and I run a macro then the data should be copied from sheet1 to sheet2 in a destinated cell.
    After copying, I want again selects another row cells and rarer action is repeated. After completing the procedure remains the selected row in sheet1.
    Is a possibility to do this using VBA. Pleease see attachment
    Attached Files Attached Files

  2. #2
    Forum Expert RobertMika's Avatar
    Join Date
    06-22-2009
    Location
    Haverhill, UK
    MS-Off Ver
    Excel 2003-13
    Posts
    1,530

    Re: Copy cells via VBA

    Would the cells from Sheet 1 are always going to the same cells in Sheet2?(overwrite)
    If you are http://www.excelforum.com/image.php?type=sigpic&userid=125481&dateline=1392355029happy with the results, please add to the contributor's
    reputation by clicking the reputation icon (star icon).




    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.
    To undo, select Thread Tools-> Mark thread as Unsolved.
    http://www.excelaris.co.uk

  3. #3
    Forum Contributor
    Join Date
    09-10-2010
    Location
    europe
    MS-Off Ver
    Excel 2007
    Posts
    149

    Re: Copy cells via VBA

    Quote Originally Posted by RobertMika View Post
    to the same cells in Sheet2?(overwrite)
    Robert, Thanks for Answer

    Yes in the first case
    In another case, I will have to make necessary changes in the VBA code that could change the destination
    In the third case, the destination is added to the next row.
    Therefore I need comments in VBA code so that I personally know how to change the VBA code
    regards

  4. #4
    Forum Contributor
    Join Date
    09-10-2010
    Location
    europe
    MS-Off Ver
    Excel 2007
    Posts
    149

    Re: Copy cells via VBA

    Hi Robert, is there a possibility to help me

  5. #5
    Forum Contributor
    Join Date
    09-10-2010
    Location
    europe
    MS-Off Ver
    Excel 2007
    Posts
    149

    Re: Copy cells via VBA

    Can anyone help me?

  6. #6
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: Copy cells via VBA

    Hi Dumy,

    Try this - I've filled in if row 3 has been selected to get you started:

    Please Login or Register  to view this content.
    HTH

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  7. #7
    Forum Contributor
    Join Date
    09-10-2010
    Location
    europe
    MS-Off Ver
    Excel 2007
    Posts
    149

    Re: Copy cells via VBA

    Quote Originally Posted by Trebor76 View Post
    Please Login or Register  to view this content.
    Hello Trebor76
    Your idea is OK but only in the case of a few lines. What if the 1000 lines, then it would have to be repeated every case of 1000.
    Is there a possibility of reduced VBA code, something like this meant the

    This is the first situation that I want to solve
    I imagine like a beginner VBA macro code something like this

    Please Login or Register  to view this content.
    Thank you for the appearance and response.

  8. #8
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: Copy cells via VBA

    In your workbook you have columns C and E from Sheet1 both linking to column F in Sheet 2. Is this correct as it will cause issues? You should have each column in Sheet1 linking to an individual column in Sheet2.

    Let me know the column mapping between the sheets and I should be able to code something for you.

    Robert

  9. #9
    Forum Contributor
    Join Date
    09-10-2010
    Location
    europe
    MS-Off Ver
    Excel 2007
    Posts
    149

    Re: Copy cells via VBA

    Quote Originally Posted by Trebor76 View Post
    In your workbook you have columns C and E from Sheet1 both linking to column F in Sheet 2. Is this correct as it will cause issues?
    Unfortunately, the situation is the way it is

    I do not know how better to explain to you my problem.
    I'm a dummy for VBA.

    Selected data are presented in a row in five columns (These columns may vary in the future if I have a different situation)
    Destination cells also in the future can be changeable, if I change the destination cell to Sheet2 then I just change a part of VBA
    It is very important that the VBA code is based on a selected range of cells, which means that the situation is changing


    I thinking like this

    Please Login or Register  to view this content.
    Or this your idea that I imagine this below

    Please Login or Register  to view this content.
    If there is a possibility this VBA code then I can change the destination cell in my future needs, I only change B4, D7, F3, C13, F11?

    I do not want to deprive you of your time, if you want to make an example I can look at your proposal.
    I apologize for my bad English

    Thank you for the appearance and response.

  10. #10
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: Copy cells via VBA

    Or this your idea that I imagine this below

    Select Code copy to clipboard
    With Sheets("Sheet2")
    .[B4].Value = Sheets("Sheet1").[first cell of the selected range].Value 'if you want change destination cells just change B4
    .[D7].Value = Sheets("Sheet1").[second cell of the selected range].Value
    .[F3].Value = Sheets("Sheet1").[third cell of the selected range].Value
    .[C13].Value = Sheets("Sheet1").[fourth cell of the selected range].Value
    .[F11].Value = Sheets("Sheet1").[fifth cell of the selected range].Value
    End With
    But as you can see from this the third and fifth cell of the selected range are going to clash

    From your posted workbook you only have seven rows for data3 on Sheet2 before it hits the heading for data5? Surely columns C and E from Sheet must have two separate columns on Sheet2?

    Robert

  11. #11
    Forum Contributor
    Join Date
    09-10-2010
    Location
    europe
    MS-Off Ver
    Excel 2007
    Posts
    149

    Re: Copy cells via VBA

    Quote Originally Posted by Trebor76 View Post
    Surely columns C and E from Sheet must have two separate columns on Sheet2?
    OK, so what I want is not possible
    Please give me your suggestion for a new situation.
    See "Sheet1" and Sheet "Trebor76" attached, of course if I have over 1000 rows on Sheet1
    Attached Files Attached Files

  12. #12
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: Copy cells via VBA

    OK, so what I want is not possible
    No, of course it's possible it's just that it will overwrite data so it seems pointless.

    Based on your latest attachment, try this

    Please Login or Register  to view this content.
    Regards,

    Robert

  13. #13
    Forum Contributor
    Join Date
    09-10-2010
    Location
    europe
    MS-Off Ver
    Excel 2007
    Posts
    149

    Re: Copy cells via VBA

    Hi Trebor76
    Thanks for the suggestion and VBA macros

    I think you did not well understood me. This your VBA macro copies more data than what I want.

    I want to VBA macro copies ONLY the selected cells
    Please see new attachment, I'm added comments to the sheets

    On Sheet1 select the row 3, only range A3: E3
    Run VBA macro
    On Sheet "Trebor76" must not be redundant data. Must be completed only cells yellow B4, C13, D7, F3, I7

    Thank you for answering
    Attached Files Attached Files

  14. #14
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: Copy cells via VBA

    I think (hope) this is what you're after:

    Please Login or Register  to view this content.
    Robert

  15. #15
    Forum Contributor
    Join Date
    09-10-2010
    Location
    europe
    MS-Off Ver
    Excel 2007
    Posts
    149

    Re: Copy cells via VBA

    Hi Robert (Trebor76)
    Thank you for reporting, your work, your VBA suggestion and your time that you set aside to communicate with me and help me.

    VBA macro that you wrote is OK and performs its function. In some other cases, the VBA code works great.
    However this does not solve my problem and this is not what I want.

    Thanks a lot again, and I do not want to deprive you of your precious time.
    I'll wait for the next help if someone wants to help me for my problem

  16. #16
    Forum Contributor
    Join Date
    09-10-2010
    Location
    europe
    MS-Off Ver
    Excel 2007
    Posts
    149

    Re: Copy cells via VBA

    Hi Robert
    I have solved half the problem with your VBA macro code

    I removed the "+1" from your code, and so got destination cells that overwrite. The problem is that I can not set the destination cell that is specified by a cell address, they are based on data in the destination column.

    I can not specify the destination cell VBA code example: B4, F7, D3, C13 and I8 on Sheet2

    My VBA code now looks like this (without +1):

    Please Login or Register  to view this content.
    Thanks

  17. #17
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: Copy cells via VBA

    I can not specify the destination cell VBA code example: B4, F7, D3, C13 and I8 on Sheet2
    That only requires a slight tweak to my code, i.e.

    Please Login or Register  to view this content.
    Robert

  18. #18
    Forum Contributor
    Join Date
    09-10-2010
    Location
    europe
    MS-Off Ver
    Excel 2007
    Posts
    149

    Re: Copy cells via VBA

    Trebor76

    That's it, That's what I asked from the beginning.
    Robert, thank you very much for your help.

    Best regards

  19. #19
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: Copy cells via VBA

    Thanks for the feedback and adding to my reputation

    I'm glad we got there in the end!!

    Regards,

    Robert

+ 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: 8
    Last Post: 07-08-2013, 06:03 AM
  2. Copy range of cells to other cells based on first cells value
    By bluestarCVO in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-28-2013, 10:02 AM
  3. [SOLVED] VBA to Copy set data, paste into set cells, then copy more & set into cells related 2 date
    By galvinpaddy in forum Excel Programming / VBA / Macros
    Replies: 99
    Last Post: 02-01-2013, 08:43 AM
  4. [SOLVED] can only copy/select visible cells w autofilter on &hidden columns, want to copy all cells
    By JTwrk in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-25-2012, 02:12 AM
  5. [SOLVED] Copy/Paste how to avoid the copy of formula cells w/o calc values
    By Dennis in forum Excel General
    Replies: 10
    Last Post: 03-02-2006, 06:50 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