VBA add date automatically when row is copied from sheet to another

lunatu

Board Regular
Joined
Feb 5, 2021
Messages
77
Office Version
  1. 2010
Platform
  1. Windows
  2. Web
Hi,

Didn't find an answer from here so lets ask this way...
Im copying data automatically from sheet1 to sheet2 and I would like there to be automatically current date in first column of the sheet2 when data is transferred.
Any idea how to solve this?

Thanks in advance! :)
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
just add this to the code doing the copying:
VBA Code:
Worksheets("Sheet2").Range("a1") = Date
 
Upvote 0
Thanks! Seems to be working, but one (silly) question still: how do I set the range correctly when I want the date be always at same row where the data is pasted (= next empty row)?
 
Upvote 0
try this:
VBA Code:
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
Worksheets("Sheet2").Range("a" & lastrow + 1) = Date
 
Upvote 0
Thank you, but still struggling with this... this code is working but it adds the date one row above, example the data is pasted to row 3 but the date is in row 2.
 
Upvote 0
what is your code for copying and pasting the data? If you post it here I then have chance to see what that is doing
 
Upvote 0
This code Im using for copy+paste:

Sub CopyCell()

Dim LR As Long, i As Long
With Sheets("Sheet1")
LR = .Range("H" & Rows.Count).End(xlUp).Row
For i = 1 To LR
If .Range("H" & i).Value = "Sales Person 1" And .Range("J" & i).Value = "Sold" Then
.Range("A" & i).Resize(1, 9).Copy Destination:=Sheets("Sheet2").Range("D" & Rows.Count).End(xlUp).Offset(1)
End If
Next i
End With
End Sub
 
Upvote 0
try trhis:
VBA Code:
Sub CopyCell()

Dim LR As Long, i As Long
With Sheets("Sheet1")
LR = .Range("H" & Rows.Count).End(xlUp).Row
For i = 1 To LR
If .Range("H" & i).Value = "Sales Person 1" And .Range("J" & i).Value = "Sold" Then
dlr = Sheets("Sheet2").Cells(Rows.Count, "D").End(xlUp).Row + 1
.Range("A" & i).Resize(1, 9).Copy Destination:=Sheets("Sheet2").Range("D" & dlr)
Sheets("Sheet2").Range("A" & dlr) = Date
End If
Next i
End With
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,918
Messages
6,122,252
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top