Home » excel » excel – VBA Timestamp or other tab not working

excel – VBA Timestamp or other tab not working

Posted by: admin May 14, 2020 Leave a comment

Questions:

I have a macro that I am running to paste data into an excelsheet. When I paste the data I want to add the time I did that so I can see when I last updated the data.
I found an easy solution for that:

[F2] = Now

looks simple and works like a charm. But then there’s a problem. This only works if the cell I want the data in is on the same tab as I am running the macro from, but i want that timestamp on another tab. I tried to change the “Overview”tab and back to “Orders” but it doesnt work:

Sheets("Overview").Select
[F2] = Now
Sheets("Orders").Select

It just gives a 400 error with no explanation. Does anybody know the solution?

How to&Answers:

Ignore the Select completely, it is not needed. Probably the error is somewhere in the logic of the other code. However, this should work:

Worksheets("Overview").Range("F2") = Now

or with different syntactic sugar:

Worksheets("Overview").[F2] = Now

How to avoid using Select in Excel VBA