+ Reply to Thread
Results 1 to 16 of 16

VBA Macro to copy values from one place to another in the sheet

  1. #1
    Registered User
    Join Date
    04-30-2018
    Location
    New York
    MS-Off Ver
    2016
    Posts
    10

    VBA Macro to copy values from one place to another in the sheet

    I have been trying to fix the below code but didn't work. Not sure why the pasterange isnt working.trying to copy data from one place to another and then loop. somehow the below code isnt going through.
    Please Login or Register  to view this content.
    Last edited by chikki985; 05-02-2018 at 10:24 PM.

  2. #2
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,700

    Re: VBA Macro to copy values from one place to another in the sheet

    Could you be so kind and put your code between code tags.

  3. #3
    Registered User
    Join Date
    04-30-2018
    Location
    New York
    MS-Off Ver
    2016
    Posts
    10

    Re: VBA Macro to copy values from one place to another in the sheet

    Thanks for pointing out. Actually cells BH1:BM1 is a formula based on pivot. Whenever the date changes in the pivot , BH1:BM1 gets updated and then each time, it should be copied to EB3:EG3.For example, When date is 04/30, BH1:BM1 is copied as values to EB3:EG3. for the next run , when date is 05/01, same cells BH1:BM1 is copied to EB4:EG4 and so on .

  4. #4
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: VBA Macro to copy values from one place to another in the sheet

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Click on Edit to open your thread, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

  5. #5
    Registered User
    Join Date
    04-30-2018
    Location
    New York
    MS-Off Ver
    2016
    Posts
    10

    Re: VBA Macro to copy values from one place to another in the sheet

    Date Source . Destination
    04/30 Cells (BH1:BM1) Cells (EB3:EG3)
    05/01 Cells (BH1:BM1) Cells (EB4:EG4)
    05/01 Cells (BH1:BM1) Cells (EB5:EG5)

    This is the logic i am trying to create.

  6. #6
    Forum Contributor
    Join Date
    03-22-2017
    Location
    Malaysia
    MS-Off Ver
    Excel 2010
    Posts
    230

    Re: VBA Macro to copy values from one place to another in the sheet

    hi please find some advice below and the solution in bottom

    Problem
    1. Name need not closed by ",
    Please Login or Register  to view this content.
    or
    Please Login or Register  to view this content.
    2. avoid use select and selection in second line. can change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    solution for question,
    Change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    change
    Please Login or Register  to view this content.
    to offset command
    Please Login or Register  to view this content.
    Last edited by BoredWorker; 05-02-2018 at 11:22 PM.
    Hope you can learn every time you visit here.

    If you still confuse on how it work, kindly ask or go to
    i) Formula - Formula (Ribbon) > Formula Auditing (Section) > Evaluate Formula > Evaluate; or
    ii) VBA/Code - Click F8 to see how it work step by step.

    It it take care of your question, Please:
    Mark tread as [Solved] [Thread Tools->Mark thread as Solved]
    ;and
    Click *Add Reputation to thank anyone solved your question.

  7. #7
    Registered User
    Join Date
    04-30-2018
    Location
    New York
    MS-Off Ver
    2016
    Posts
    10

    Re: VBA Macro to copy values from one place to another in the sheet

    Thank You. Looping works fine but it still has small problem. I need the below but somehow the latest value in cells BH1:BM1 is copied to EB3:EG4 instead of EB4:EG4.

    Date Source Destination
    04/30 Cells (BH1:BM1) Cells (EB3:EG3)
    05/01 Cells (BH1:BM1) Cells (EB4:EG4)

  8. #8
    Forum Contributor
    Join Date
    03-22-2017
    Location
    Malaysia
    MS-Off Ver
    Excel 2010
    Posts
    230

    Re: VBA Macro to copy values from one place to another in the sheet

    it due to your code is stated it copy EB3:EG4

    Please Login or Register  to view this content.
    change to
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    04-30-2018
    Location
    New York
    MS-Off Ver
    2016
    Posts
    10

    Re: VBA Macro to copy values from one place to another in the sheet

    Thanks Boredworker. Should I add any loop condition as the second line should be added to "EB4:EG4"?

  10. #10
    Forum Contributor
    Join Date
    03-22-2017
    Location
    Malaysia
    MS-Off Ver
    Excel 2010
    Posts
    230

    Re: VBA Macro to copy values from one place to another in the sheet

    nope,
    as the offset is cover that portion,

    you just need to put the offset command in the loop.

    *if you can please try to use F8 to see how the code work line by line.
    **attach the sample excel file as well, as it easy to test the code. (*remember to remove sensitive data)

  11. #11
    Registered User
    Join Date
    04-30-2018
    Location
    New York
    MS-Off Ver
    2016
    Posts
    10

    Re: VBA Macro to copy values from one place to another in the sheet

    Below is the final code i am using but still has some issues.

    Please Login or Register  to view this content.

  12. #12
    Forum Contributor
    Join Date
    03-22-2017
    Location
    Malaysia
    MS-Off Ver
    Excel 2010
    Posts
    230

    Re: VBA Macro to copy values from one place to another in the sheet

    if can please put an example file to let us to test as well instead of just putting code here.
    with code only we cannot have test as we do not know what result you needed.

    i think should put the offset in to the loop.
    Please Login or Register  to view this content.
    Change to
    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    04-30-2018
    Location
    New York
    MS-Off Ver
    2016
    Posts
    10

    Re: VBA Macro to copy values from one place to another in the sheet

    I have attached the sample data. Please take a look. I am still getting the error.
    Attached Files Attached Files

  14. #14
    Forum Contributor
    Join Date
    03-22-2017
    Location
    Malaysia
    MS-Off Ver
    Excel 2010
    Posts
    230

    Re: VBA Macro to copy values from one place to another in the sheet

    Hi chikki985,

    The error is cause by the offset function.
    should be add "Set" in front.

    I change your code abit, use of "With" made the structure more tidy.
    below line is add to faster the process, if you want to see how it work line by line, please delete this line.
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.

  15. #15
    Registered User
    Join Date
    04-30-2018
    Location
    New York
    MS-Off Ver
    2016
    Posts
    10

    Re: VBA Macro to copy values from one place to another in the sheet

    Awesome Boredworker. You are a pro!!It works splendidly.Thank You so much . If I need to edit the code in such a way so that it automatically selects each date from the pivot in decending order and paste the data as you did in the above code . How can we do this?

  16. #16
    Forum Contributor
    Join Date
    03-22-2017
    Location
    Malaysia
    MS-Off Ver
    Excel 2010
    Posts
    230

    Re: VBA Macro to copy values from one place to another in the sheet

    If I need to edit the code in such a way so that it automatically selects each date from the pivot in decending order and paste the data as you did in the above code . How can we do this?
    Actually all the step is same as what you give, just the structure is change (just let it look nicer).

    except this one: (Add "Set" in front), this is the reason why previous code cann't work.
    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. Macro copy from one sheet and paste values in NEXT VISIBLE SHEET & then ACTIVATE IT.
    By acsishere in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-10-2017, 04:54 AM
  2. [SOLVED] Search for values, copy matching rows to existing sheet in a specific place?
    By sordosxls in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 05-12-2016, 06:27 PM
  3. Macro: Copy Active Sheet, Make Values Only, then Save Copy
    By brendangroff in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-10-2015, 04:34 PM
  4. Get the SUM of identical values from one sheet and place it on another sheet
    By stoey in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-14-2014, 11:49 AM
  5. macro to copy values on one sheet based on the values of another sheet.
    By buntalan80 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-25-2013, 09:09 AM
  6. place values on the right date in another sheet
    By keis386 in forum Excel General
    Replies: 1
    Last Post: 08-10-2011, 07:42 AM
  7. Calculate values in one sheet and place result in another sheet
    By maximpinto in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-23-2010, 07:15 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