+ Reply to Thread
Results 1 to 23 of 23

Copy data using a Macro

  1. #1
    Registered User
    Join Date
    06-14-2012
    Location
    Durban
    MS-Off Ver
    Excel 2007
    Posts
    21

    Copy data using a Macro

    Using a macro how do I copy a range of cells, with formulas, from one range to the next range/column? Then copy the new range of cells to the next column when the macro is run again?

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Copy data using a Macro

    Please provide some more details like -

    1. Are the ranges in the same workbook?
    2. If in the same workbook, are they in the same worksheet or different worksheets?
    3. What are the cell addresses of the ranges?
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Registered User
    Join Date
    09-14-2011
    Location
    Sweden
    MS-Off Ver
    Excel 2007
    Posts
    64

    Re: Copy data using a Macro

    Something like this?
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    06-14-2012
    Location
    Durban
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Copy data using a Macro

    Quote Originally Posted by arlu1201 View Post
    Please provide some more details like -

    1. Are the ranges in the same workbook? - YES
    2. If in the same workbook, are they in the same worksheet or different worksheets? ONE WORK SHEET
    3. What are the cell addresses of the ranges?
    Basically I want to copy the formulas from eg: B1-B10 and paste it into C1-C10, the next time you run this macro it must take the formulas from C1-C10 and paste it into D1-D10. Every time you run the macro it must move on

  5. #5
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Copy data using a Macro

    Did you try the code Rob gave you?

  6. #6
    Registered User
    Join Date
    06-14-2012
    Location
    Durban
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Copy data using a Macro

    Hi...

    Yeah I tried what Rob said, it works but it copies the entire column. I want to copy a range eg B1:B10 to C1:C10...then when I run it the next time it must copy from C1:C10 to D1:D10...

  7. #7
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Copy data using a Macro

    Seems to me that:
    Please Login or Register  to view this content.
    Would suffice

  8. #8
    Registered User
    Join Date
    06-14-2012
    Location
    Durban
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Copy data using a Macro

    Thank you for all the help. I am almost where i need to be. Just a few more questions now that the main bit is sorted.

    Using the same or another macro I now I need to find out how to copy and paste special the previous range
    and is it possible for then use Kyle123's macro on multiple worksheets?

  9. #9
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Copy data using a Macro

    Mine will work on the active sheet, so yes, it does that by default.

    My method won't work for paste special though. What is it you are needing? Just the values? If so
    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    06-14-2012
    Location
    Durban
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Copy data using a Macro

    Thanks Kyle. Let me see if I can explain a bit better what I require..

    Ok I have formulas in 17 worksheets in the same place eg B12:B22. When I run the macro I want it to copy that formula to C12:22, then copy and paste special values in B12:B22. The next time I run the macro it must now copy the formulas for C12:C22 to D12:D22, then copy and paste special values in C12:C22 and so on

  11. #11
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Copy data using a Macro

    Maybe:
    Please Login or Register  to view this content.
    Or if you want the ranges in the formulas to increment:
    Please Login or Register  to view this content.
    Last edited by Kyle123; 06-15-2012 at 05:38 AM.

  12. #12
    Registered User
    Join Date
    06-14-2012
    Location
    Durban
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Copy data using a Macro

    Thank u kyle this works, but ..
    where u have "ActiveSheet.Columns.Count" is there a way to change this so that it simulantenously does, "sheet1, sheet2 , sheet 3 etc" whilst using the same range?
    Also where you have "Resize(10)" say for example I have 10 rows, which pulls through fine, then there is 2 empty rows and then another 2-3rows that I need brought over so example: "A1:A10 and then A13:A16"

  13. #13
    Registered User
    Join Date
    06-14-2012
    Location
    Durban
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Copy data using a Macro

    where u have "ActiveSheet.Columns.Count" is there a way to change this so that it simulantenously does, "sheet1, sheet2 , sheet 3 etc" whilst using the same range?
    Also where you have "Resize(10)" say for example I have 10 rows, which pulls through fine, then there is 2 empty rows and then another 2-3rows that I need brought over so example: "A1:A10 and then A13:A16"

  14. #14
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Copy data using a Macro

    Potentially:
    Please Login or Register  to view this content.

  15. #15
    Registered User
    Join Date
    06-14-2012
    Location
    Durban
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Copy data using a Macro

    Quote Originally Posted by Kyle123 View Post
    Potentially:
    Please Login or Register  to view this content.
    Hi Kyle, I have attempted this and it doesnt work..

    the ffg line is incorrect?
    With ws.Cells(1, ws.Columns.Count).End(xlToLeft).Range(Cells(1, 1), Cells(ws.Rows.Count, 1).End(xlUp))

  16. #16
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Copy data using a Macro

    What error do you get? At a guess you have no data in one of your worksheets

  17. #17
    Registered User
    Join Date
    06-14-2012
    Location
    Durban
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Copy data using a Macro

    there is no specific error it just highlights that line in yellow?

  18. #18
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Copy data using a Macro

    It must say something?

  19. #19
    Registered User
    Join Date
    06-14-2012
    Location
    Durban
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Copy data using a Macro

    Do you think its at all possible for me to get your email address as it wont let me paste a screen dump here? maybe i can mail you the situation I am getting?

  20. #20
    Registered User
    Join Date
    06-14-2012
    Location
    Durban
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Copy data using a Macro

    Run-time error '1004':

    Application-defined or object -defined error

  21. #21
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Copy data using a Macro

    Try This:
    Please Login or Register  to view this content.

  22. #22
    Registered User
    Join Date
    06-14-2012
    Location
    Durban
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Copy data using a Macro

    Great thank you, it works!! whew!

    Is there a way though that this may only run for specific sheets, so I have 17 worksheets, I only require this to run for sheet1 , sheet 2 and sheet 3?

  23. #23
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Copy data using a Macro

    Like this:
    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)

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