Is it possible to have static timestamp each time you run macro a new one is added to the row?

rebeila

New Member
Joined
Oct 6, 2023
Messages
17
Office Version
  1. 365
Platform
  1. Windows
I already have a code that enters data every time in a next row.
Now I would like to do the same with time but that it does not change at all. Basically I need a keyboard shortcut: ctrl+shift+:

Sub cardpackinsp()

Dim ws As Worksheet
Dim nextRow As Long

Set ws = Sheets("Data3")

nextRow = ws.Cells(ws.Rows.Count, "C").End(xlUp).Row + 1


Range("'Data1'!$B6") = "=TODAY()"



ans = msgbox("Corrcet?", vbQuestion + vbYesNoCancel)

Select Case ans
Case vbYes
ws.Cells(nextRow, "C").Value = "Pass"
Case vbNo
ws.Cells(nextRow, "C").Value = "Fail"
End Select

ans = msgbox("Correct QTY?", vbQuestion + vbYesNoCancel)

Select Case ans
Case vbYes
ws.Cells(nextRow, "D").Value = "Pass"
Case vbNo
ws.Cells(nextRow, "D").Value = "Fail"
End Select

ans = msgbox("Position OK?", vbQuestion + vbYesNoCancel)
Select Case ans
Case vbYes
ws.Cells(nextRow, "E").Value = "Pass"
Case vbNo
ws.Cells(nextRow, "E").Value = "Fail"
End Select
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
In VBA, if you use:
VBA Code:
Range(...) = Date
it will hard-code the current date in that cell.

If you use:
VBA Code:
Range(...) = Now()
it will hard-code the current date & time in that cell.

By the way, this is NOT a valid range reference:
VBA Code:
Range("'Data1'!$B6")
It should be:
VBA Code:
Sheets("Data1").Range("B6")
 
Upvote 0
In VBA, if you use:
VBA Code:
Range(...) = Date
it will hard-code the current date in that cell.

If you use:
VBA Code:
Range(...) = Now()
it will hard-code the current date & time in that cell.

By the way, this is NOT a valid range reference:
VBA Code:
Range("'Data1'!$B6")
It should be:
VBA Code:
Sheets("Data1").Range("B6")
Thank it almost works perfectly, but now I would like to make it go one row done each time i run macro, it works for everything else but not the time.
 
Upvote 0
Thank it almost works perfectly, but now I would like to make it go one row done each time i run macro, it works for everything else but not the time.
That was not part of your original question here, but didn't we already address about how to move down one row in your other thread I helped you with last week?
You should be able to apply the same logic. I showed you how to find the last row with data, and then just add one to that row number.

Actually, you already have a "nextRow" calculation in your code, so you would just have to follow the same logic and do the same thing for the other sheet.
 
Upvote 0
That was not part of your original question here, but didn't we already address about how to move down one row in your other thread I helped you with last week?
You should be able to apply the same logic. I showed you how to find the last row with data, and then just add one to that row number.
I will figure it out, but I just thought I that the existing code would work:

Dim ws As Worksheet
Dim nextRow As Long

Set ws = Sheets("Data3")

nextRow = ws.Cells(ws.Rows.Count, "C").End(xlUp).Row + 1

Changing C to B bc of time
 
Upvote 0
If you want to find the last row with data in column B of your "Data3" sheet, you need to update the column reference to reflect that, i.e.
Rich (BB code):
nextRow = ws.Cells(ws.Rows.Count, "B").End(xlUp).Row + 1
Is that the problem you are having?

If not, I am afraid I do not understand what you are asking.
 
Upvote 1
Solution
In VBA, if you use:
VBA Code:
Range(...) = Date
it will hard-code the current date in that cell.

If you use:
VBA Code:
Range(...) = Now()
it will hard-code the current date & time in that cell.

By the way, this is NOT a valid range reference:
VBA Code:
Range("'Data1'!$B6")
It should be:
VBA Code:
Sheets("Data1").Range("B6")
This worked:
ws.Cells(nextRow, “b”).Value = now()

Thanks for help
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,179
Members
453,021
Latest member
Justyna P

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