VBA script to create an interger value of the current date and time stamp

KlayontKress

Board Regular
Joined
Jan 20, 2016
Messages
67
Office Version
  1. 2016
Platform
  1. Windows
I'm looking to modify a VBA code to create a unique date and time stamp. The code I have so far is

Code:
    Sheets("Route Import").Cells(x, 1).Value = Int(CDbl(Now()))

This gives me the integer value of the date but I also need the time because the macro I'm using will go to the next line and create a route id for the next person and Ineed unique values across days. Right now, the existing code
Code:
Sheets("Route Import").Cells(x, 1).Value = Round(((999 - 100 + 1) * Rnd + 100), 0) & Round(((999 - 10 + 1) * Rnd + 100), 0) & Round(((999 - 10 + 1) * Rnd + 100), 0)
is generating "Random" numbers that are repeating day to day and this is messing up the scheduling program because it's trying to add what is supposed to be a new day's route information to a past day's route because the route id's are the same. I found the code that was generating this number and had the idea of using the date time stamp to generate a unique number number but I lack the knowledge on how to get the date and time together in an integer.

The code to generate this route id repeats until it creates a unique route id for all of the service techs that day so I need it to pull the current system time to a fraction of a second (a millisecond may work) so that if it can process multiple times in a single second, each entry is unique from the others.


Any help is greatly appreciated.


Thanks,
 
Last edited:
I am late to this thread and while I skimmed the responses, I did not try to fully digest them. With that said, would the following produce the result the OP was after...

MsgBox [SUBSTITUTE(INT(NOW())&TEXT(NOW(),"hhmmss.0"),".","")]
 
Upvote 0

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

Forum statistics

Threads
1,223,903
Messages
6,175,286
Members
452,631
Latest member
a_potato

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