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.
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]
You mean the data in sheet1 column C? definitely yes.
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]
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.
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]
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.
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]
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]
Hello arlette,
thank you so much..!
Best regards,
arem28
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks