Hello Sir,
I have a simple stock that I have consult with our board before.
For now, I would like to create a time stamp, copy name in column C and input data to another sheet when user has click OK button.
Example:
If I input 10 in the box and click OK, It will store like in the result picture.
Next, After I click OK then store the result finish, I would like to create time stamp in TimeStamp work sheet in every click OK.
Example: Result should be like this in TImeStamp worksheet.
Here is my code and file My file.
I have try to create the time stamp as you can see in the code. But it not working as my expected
I have a simple stock that I have consult with our board before.
For now, I would like to create a time stamp, copy name in column C and input data to another sheet when user has click OK button.
Example:
If I input 10 in the box and click OK, It will store like in the result picture.
Input 10 | current result |
|
Next, After I click OK then store the result finish, I would like to create time stamp in TimeStamp work sheet in every click OK.
Example: Result should be like this in TImeStamp worksheet.
Here is my code and file My file.
I have try to create the time stamp as you can see in the code. But it not working as my expected
VBA Code:
Sub addStock()
Dim balanceStock As Double
Dim Col As Integer
'Check imput Applies columns E & F only
If ActiveCell.Column < 5 Or ActiveCell.Column > 6 Then Exit Sub
'Find current mont
Col = 2 * Month(Now) + 6
balanceStock = InputBox("Amount?")
With ActiveCell
.Value = .Value + balanceStock
If balanceStock < 0 Then Col = Col + 1
Cells(.Row, Col) = Cells(.Row, Col) + balanceStock
End With
'Copy and time stamp (not working now)
Dim wsYearlyStock As Worksheet 'define source sheet
Set wsYearlyStock = ThisWorkbook.Worksheets("YearlyStock")
Dim wsTimeStamp As Worksheet 'define destination sheet
Set wsTimeStamp = ThisWorkbook.Worksheets("TimeStamp")
Dim DestRow As Long
DestRow = 2 'start in row 5 in destination sheet
Dim Rng As Range
For Each Rng In Selection.Areas
Rng.Resize(, 1).Copy Destination:=wsTimeStamp.Cells(DestRow, "C") 'copy A to B
DestRow = DestRow + Rng.Rows.Count 'move DestRow to next free row
Next Rng
End Sub