PDA

View Full Version : Solved: automaticaly fill date of write



danovkos
02-10-2010, 05:38 AM
Hi all,
a few days ago, some greate guys help me with problem about filling all data in sheet. http://www.vbaexpress.com/forum/showthread.php?t=30112

Now i try to do folowing.
I want always if user in sheet KRIZ and DE fill any value in column B, macro fill actual date in the same row in column K before save wb. I mean, when he will save wb, it fill this date and then save wb.

I try it with other words - if i fill some data to B in row 20, then row 21 and 23, when i will save the wb, it fill in each filled row (20-23) in column K actual date - as value of course and after this it save wb.

edit: sorry and if it is possible to column L it write user name.


Pls. how can i do this?
thx a lot

lucas
02-10-2010, 05:53 AM
Try this. If you enter anything into column B, the date is updated to todays date in column K.

It's sheet change code so you select the sheet tab you want to run it on and right click the tab....select "view code" and paste your code in that module:

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Row = 1 Then Exit Sub
If Target.Column <> 2 Then Exit Sub
Application.EnableEvents = False
Cells(Target.Row, "k") = Int(Now())
Application.EnableEvents = True
End Sub


Example attached.

lucas
02-10-2010, 06:03 AM
To add the username to column L:


Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Row = 1 Then Exit Sub
If Target.Column <> 2 Then Exit Sub
Application.EnableEvents = False
Cells(Target.Row, "k") = Int(Now())
Cells(Target.Row, "l") = Environ("USERNAME")
Application.EnableEvents = True
End Sub

danovkos
02-10-2010, 07:29 AM
IT WORKs perfect :)
thx lucas,
now i try only to figured out,how write date in format
DD.mm.yy HH:mm

i tried this but doesnt works:

Cells(Target.Row, "k") = Format(Now, "dd" & "." & "mm" & "." & "yy" & " " & "hh:mm:ss")

lucas
02-10-2010, 07:40 AM
Cells(Target.Row, "k") = Now()

danovkos
02-10-2010, 07:43 AM
yes of course, so simply:banghead:

thx for your quick help
:hi: