+ Reply to Thread
Results 1 to 10 of 10

Thread: how to copy data from one worksheet to another by using macro

  1. #1
    Registered User
    Join Date
    02-03-2012
    Location
    philippines
    MS-Off Ver
    Excel 2007
    Posts
    10

    how to copy data from one worksheet to another by using macro

    Hi!
    Please help create a macro that would update my data on a daily basis in sheet 2. If there’s an input data in “qty.” in sheet1, it should be copied accordingly in sheet2 whereas the date must be updated also.

    If there's anything more i should do please let know. thank you...

    Please refer to the worksheet attached.

    regards,
    arem28daily record.xlsx
    Last edited by arem28; 02-08-2012 at 11:04 PM.

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

    Re: how to copy data from one worksheet to another by using macro

    Would Sheet1 be cleared each day to put in the new values?
    Cheers,
    Arlette

    If I 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
    02-03-2012
    Location
    philippines
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: how to copy data from one worksheet to another by using macro

    You mean the data in sheet1 column C? definitely yes.

  4. #4
    Forum Moderator arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    4,383

    Re: how to copy data from one worksheet to another by using macro

    Use this code -
    Option Explicit
    Dim lcol As Long
    Dim lrow As Long
    
    Sub update_daily()
    
    With Worksheets("Sheet2")
        lcol = .Range("XFD2").End(xlToLeft).Column
        .Cells(2, lcol + 1).Value = Date
        lrow = .Range("A" & Rows.Count).End(xlUp).Row
        .Range(.Cells(3, lcol + 1), .Cells(lrow, lcol + 1)).FormulaR1C1 = "=VLOOKUP(RC1,Sheet1!C1:C3,3,0)"
        .Range(.Cells(3, lcol + 1), .Cells(lrow, lcol + 1)).Copy
        .Cells(3, lcol + 1).PasteSpecial , Paste:=xlValues
    End With
    
    With Worksheets("Sheet1")
        lrow = .Range("C" & Rows.Count).End(xlUp).Row
        .Range("C3:C" & lrow).ClearContents
    End With
    
    End Sub
    Cheers,
    Arlette

    If I 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]

  5. #5
    Registered User
    Join Date
    02-03-2012
    Location
    philippines
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: how to copy data from one worksheet to another by using macro

    As i tried using the code there’s no doubt that you have made it right. It just that i think, we are having trouble using vlookup. On my observation, it doesn’t function properly whenever it is used on the same workbook. So, i want to try it on different workbook. Could you still help me? Just in case it’s necessary for details sake, the 2nd workbook can be named as "daily record_2" and same data in sheet2 workbook1 can be found in sheet2 workbook2 which is the destination of the copied data. Your help is very much appreciated and will appreciate more... thank you.

  6. #6
    Forum Moderator arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    4,383

    Re: how to copy data from one worksheet to another by using macro

    I dont think vlookup will have a problem while working in the same workbook. Why do you say its not working?
    Cheers,
    Arlette

    If I 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]

  7. #7
    Registered User
    Join Date
    02-03-2012
    Location
    philippines
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: how to copy data from one worksheet to another by using macro

    I didn't said that it's not working, what i said is that "it doesn’t function properly whenever it is used on the same workbook" and that was on my own observation. if it's fine with you, you can try it for you self buy entering different sequence of data in sheet1 "column C" as i am supposed to enter a new sort of data each day. thanks again... If you didn't find a problem well then it's ok, if you do i would love to hear if you had a solution.

  8. #8
    Forum Moderator arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    4,383

    Re: how to copy data from one worksheet to another by using macro

    Oh ok....got you this time .

    Well, i have been using vlookup a lot and have used it within the same workbook. I will provide you an alternate solution using 2 workbooks as you suggested and see if it works perfectly as you need it.
    Cheers,
    Arlette

    If I 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]

  9. #9
    Forum Moderator arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    4,383

    Re: how to copy data from one worksheet to another by using macro

    I just realised one more aspect regarding your test file above (while i was creating an alternate code). I found that product 1 to product 10 in sheet 1 were written with one extra space at the end (some of them), while product 1 to product 10 in sheet 2 didnt have the space. For e.g.Product 2 on sheet1 doesnt have the space at the end and sheet2 has it. So this will result in the vlookup not working. You need to remove these spaces.

    You can use this revised code -
    Option Explicit
    
    Dim lcol As Long
    Dim lrow As Long
    
    Sub update_daily()
    
    With Worksheets("Sheet2")
        lcol = .Range("XFD2").End(xlToLeft).Column
        .Cells(2, lcol + 1).Value = Date
        lrow = .Range("A" & Rows.Count).End(xlUp).Row
        .Range(.Cells(3, lcol + 1), .Cells(lrow, lcol + 1)).FormulaR1C1 = "=VLOOKUP(RC1,'[daily record_2.xlsx]Sheet1'!C1:C3,3,0)"
        .Range(.Cells(3, lcol + 1), .Cells(lrow, lcol + 1)).Copy
        .Cells(3, lcol + 1).PasteSpecial , Paste:=xlValues
    End With
    
    With Workbooks("daily record_2.xlsx").Worksheets("Sheet1")
        lrow = .Range("C" & Rows.Count).End(xlUp).Row
        .Range("C3:C" & lrow).ClearContents
    End With
    
    End Sub
    Cheers,
    Arlette

    If I 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]

  10. #10
    Registered User
    Join Date
    02-03-2012
    Location
    philippines
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: how to copy data from one worksheet to another by using macro

    Hello arlette,


    thank you so much..!


    Best regards,
    arem28

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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.2.0