+ Reply to Thread
Results 1 to 22 of 22

Copy data from one sheet to another with the help of a code

  1. #1
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,147

    Copy data from one sheet to another with the help of a code

    How do I attach my file..?
    Last edited by RAJESH SHAH; 11-26-2021 at 03:31 PM.

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Copy data from one sheet to another with the help of a code

    Welcome to the forum

    Please attach a sample workbook (not a picture or pasted copy). Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  3. #3
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,147

    Re: Copy data from one sheet to another with the help of a code

    I have attached my sample file along with this message.
    This sheet contains data in different columns. As the cells contain formulas, I am trying to copy the data to the sheet “Copy” with the help of paste special > values. The columns containing the amounts may be different in different cases. Sometimes I have to select the data from A:F in this case and sometimes it is up to 31 columns or more. How do I copy the data with date to the sheet “Copy” with the help of a code.?
    This code gives me the correct answer if the data is in columns A: AE(31 columns), but in a different scenario if the columns are less than that I get an error but the code has given the right solution. How can I avoid that error.? I am getting an error at this line of cide. (Run Time Error 1004). Please note: I am getting the required solution after I press end in the error box. I just want to avoid the error message.
    With .Range(Cell.Offset(1), Cell.End(xlDown))
    .Copy Sheets("Daily").Range("B" & Rows.Count).End(xlUp).Offset(1)
    Cell.Copy Sheets("Daily").Range("A" & Rows.Count).End(xlUp).Offset(1).Resize(.Count)
    End With
    Attached Files Attached Files
    Last edited by RAJESH SHAH; 11-25-2021 at 05:45 PM.

  4. #4
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,147

    Re: Copy data from one sheet to another with the help of a code

    Option Explicit
    Dim Cell As Range
    Sub Append()
    Sheets("Extract").Select
    Range("A1:AE619").Select
    Selection.Copy
    Sheets("Copy").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    Range("A1:AE1").Select
    Application.CutCopyMode = False
    Selection.NumberFormat = "m/d/yyyy"
    Range("A1").Select
    Dim Cell As Range
    Sheets("Copy").Select
    With Sheets("Copy")
    For Each Cell In .Range("A1", .Cells(1, Columns.Count).End(xlToLeft))
    With .Range(Cell.Offset(1), Cell.End(xlDown))
    .Copy Sheets("Daily").Range("B" & Rows.Count).End(xlUp).Offset(1)
    Cell.Copy Sheets("Daily").Range("A" & Rows.Count).End(xlUp).Offset(1).Resize(.Count)
    End With
    Next Cell
    End With
    Sheets("Daily").Select
    Range("A2").Select
    End Sub
    This is the full code. I didn't save the sheet as xlsm. Hence, the code must have not been uploaded

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

    Re: Copy data from one sheet to another with the help of a code

    How far does this get you?
    Please Login or Register  to view this content.
    Can you please explain what yuo want to accomplish with this.
    Please Login or Register  to view this content.

    Attachment 756936
    Last edited by jolivanes; 11-26-2021 at 03:15 AM.

  6. #6
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,147

    Re: Copy data from one sheet to another with the help of a code

    Thanks for the response Jolivanes. First, I am trying to copy the data from sheet Extract to Sheet Copy. To remove the formula from sheet Extract I am using Paste Special > values. Then I am seperate the dates and amounts of the whole data in 2 columns in sheet Daily vertically. If you have run the code I shared, you will see an error. If you check the result, I mean the total of all amounts in Extract and match with Daily it is matched.

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

    Re: Copy data from one sheet to another with the help of a code

    I don't run code that does not work properly.
    You don't need sheet "Copy" to copy and paste values from the 2nd row in sheet "Extract" to sheet "Daily"
    So again I ask, what do you want to do?
    Copy values from Columns A and B from the 2nd row down in sheet "Extract" and paste in sheet "Daily"? To where in sheet daily?

  8. #8
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,147

    Re: Copy data from one sheet to another with the help of a code

    I want to copy the values from Extract and paste in sheet "Daily", Dates in Column A2 and Amount in column B2 but without the formula. Check this sample file
    Attached Files Attached Files
    Last edited by RAJESH SHAH; 11-26-2021 at 02:25 AM. Reason: attaching file

  9. #9
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,147

    Re: Copy data from one sheet to another with the help of a code

    Before I run the code the sheets Copy and Daily are blank. The sheet Extract only contains data. Delete the contents of Copy and Daily and then run the code. You will understand what I am trying to achieve.

  10. #10
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,147

    Re: Copy data from one sheet to another with the help of a code

    GTG. Will be back in around 4 hours.

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

    Re: Copy data from one sheet to another with the help of a code

    This assumes, as you mentioned, that sheet "Daily" is empty.
    You don't need sheet "Copy", straight from one sheet into the other.
    You see now how important it is to attach a workbook with before and after.
    Please Login or Register  to view this content.
    It's not only you that GTG, I am going to get my beauty sleep.

    Let us know if this does what you want, and remember the attachment from Post #5.
    Last edited by jolivanes; 11-26-2021 at 03:17 AM.

  12. #12
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,147

    Re: Copy data from one sheet to another with the help of a code

    Jolivanes. I am learning accounts at a CA office where they do a lot of work manually. Being aware what excel can do, I try new ways to make the work easier and faster. After I learn and understand each topic fully, I try to create small application which will help in getting days of work in minutes. This is one of them. This work takes around 10 days to complete it manually. I am trying to create an app where it could be done in one hour. As I am new to coding, I try and write a few codes but when the codes are too complicated to write, I get help from the excel forums. I can get the code written through commercial services but I would miss the fun of learning and creating.

  13. #13
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,147

    Re: Copy data from one sheet to another with the help of a code

    Regarding this project, I have created 8 macros with 7 different sheets, all the macro buttons placed in the first sheet. Since, I am getting an error in one of the sheets, I will not able to hide and protect the sheets which would be my next step, So, the code you shared is working perfectly except that I didn't mention that the Extract sheet contains amounts in the 621, 622 and 623 rows. Sorry about that. Row 621 is the sum of total in rows 2 to 619, row 622 is the exact total expected from cell 2 to 619 (result of a formula) and row 623 is the difference if any between 621 and 622. So, in your code if you select the data from each column from cell 2 to cell 619 then I would get the perfect match. If this code works, my project will be as good as over. I have marked cells yellow in the Daily Sheet for your reference.
    Attached Files Attached Files

  14. #14
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,147

    Re: Copy data from one sheet to another with the help of a code

    Sorry once again, I didn't share the entire details. My mistake.

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

    Re: Copy data from one sheet to another with the help of a code

    Is this done to check if all the data from the one sheet has been transferred to the other sheet?
    If so, that is not needed as that is what the code does. However, it is no problem adding that in.
    You mention that Row 621 is the sum of Column B. I assume that that should be "below the last cell" in Column B as the columns in Sheet "Extract" can be of different lengths and consequently the length of Column B is not always the same.
    Is that so?

  16. #16
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,147

    Re: Copy data from one sheet to another with the help of a code

    The length of the amounts at any time can be only up to Row 619 or less in each column. It should not take the amount of Row 621 onwards.

  17. #17
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,147

    Re: Copy data from one sheet to another with the help of a code

    This is why I used this formula...
    For Each Cl In .Range("A1", .Cells(1, Columns.Count).End(xlToLeft))
    With .Range(Cl.Offset(1), Cl.End(xlDown))
    .Copy Sheets("Daily").Range("B" & Rows.Count).End(xlUp).Offset(1)
    Cl.Copy Sheets("Daily").Range("A" & Rows.Count).End(xlUp).Offset(1).Resize(.Count)
    End With
    Next Cl
    This was for copying the data from Extract - Copy - Daily

  18. #18
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,147

    Re: Copy data from one sheet to another with the help of a code

    From the copy sheet the last 3 columns 621, 622 and 623 were not copied. Hence I used to get the Daily data without the totals.

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

    Re: Copy data from one sheet to another with the help of a code

    Did you read the attachment in Post #5?

    Change this line
    Please Login or Register  to view this content.
    to this
    Please Login or Register  to view this content.
    If you sum the values of Column A, where do you want that pasted? And what about the other Columns?
    For Column A, should that not be in Cell C17 in "Daily" sheet?
    And for Column B in C23?

  20. #20
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,147

    Re: Copy data from one sheet to another with the help of a code

    Perfect. Thanks a ton Jolivanes. About attachment #5, I already explained in attachment #13. Is there something else other than that.? I have to hide some of the sheets and protect the macro so that it may not be altered by mistake by the user. That I think I will do it. Thanks once again.

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

    Re: Copy data from one sheet to another with the help of a code

    The attachment is about using code tags, nothing else.
    If that's it, good luck and stay safe.

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

    Re: Copy data from one sheet to another with the help of a code

    BTW, if you want the sum of each column in Column C of "Daily" sheet, use this code.
    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. VBA Code for Multiple sheet Pivot Table Data copy and paste to another sheet
    By neeraj1418 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-13-2021, 06:46 AM
  2. [SOLVED] VBA code for copy data to another sheet, do amendment in that code
    By keshavtale in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 05-07-2021, 10:30 AM
  3. [SOLVED] Vba code to copy unique email id data from input sheet to output sheet
    By UPA in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-09-2017, 07:19 AM
  4. [SOLVED] Vba code to copy spacific data from Raw data sheet to output sheet
    By Rajesh shishodia in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-09-2016, 02:32 AM
  5. VBA code to copy data from one sheet to another
    By kasun in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-19-2014, 05:38 AM
  6. VBA CODE to Copy Paster data from one sheet to other sheet on a daily basis
    By aravindkm in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 12-26-2013, 12:06 PM
  7. Replies: 1
    Last Post: 03-28-2013, 02:49 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