allrounder,
Worksheetchange is a worksheet event available through the VBA editor. When the left hand selection window shows worksheet, then all the events available are shown in a dropdown list from the righthand window. Selection an event such as 'Change' will drop
Code:
public sub worksheetChange(ByVal Target As Excel.Range)
end sub
into the VBA editor. The 'Target' is an Excel range variable, which in this case is the cell (any cell is also a range consisting of one cell). It's an object with its attendant properties. This subroutine will be triggered whenever something is entered into a cell on a worksheet containing the subroutine. It triggers when you press enter or exit the cell some other way. It will trigger regardless of whether you left data in the cell or erased it before exiting, but if nothing was done in the cell it's not triggered.
Every column (A,B,C,D, ...) is associated with a number, hence column A is column 1, column B is column 2 and so on. One of the properts of the target (the cell in this case) is it's column number. Hence whenever the Change procudure is triggered, the column number (and row also using target.row) can be queried to determine the location of the cell.
The Target.Offset(0,2).text is saying, look in a cell that is offset from the cell in question by in 0 rows and 2 columns (not column 2 but target.column + 2 and set it's .text property to "" (Nothing?). You could get at any cell this way, if you know it's position relative to your target cell.
Target.Offset(0,2).value is the value property of target, whereas .text = somevalue, would set the format of the data in the cell to text, .Value will except other formats. In this case you are using VBA format function to set time in the cell in the format you want. ie. 'Now' is a function returning (I think, date and time of the instant you executed the line of code. the "h:nn APMM" layout the format of the time you enter into the cell. The cells format is now set to Date/Time
This is rather long winded. Hope it helps
Enter your message below
Sign in or Join us (it's free).