If you are a busy admin nerd like me and have created a Google Doc or Sheet on the fly to meet your company’s demands for something or another, you probably also have a few Sheets lying around that are not 100% right. That obsessive-compulsive nature in you is niggling the back of your mind saying, “You can do this better!”
But the day-to-day race to get things done takes over and you move on to more pressing matter.
Until the next time you have to look at that Google Sheet and it starts bugging you again. Well, until you have a moment to fix it.
For me each week I had a sign-up sheet for a makeup test for students. The coordinators who would add students to the sheet required that in the header rows, the date of the next Makeup Test be added for each week.
The makeup test was always at the same time each week: Monday at 15:30. I would then need to prefix this with the day and month. So it would look something like this:
Monday 28 Jan at 15:30
My original approach then was to open the sheet and change the date manually each week. Okay, I admit that on not just one occasion I forgot to change the date much to the glee of the most persnickety of the coordinators who could happily call me out on my failure. Grrr.
I knew I could make this more efficient. I knew I could probably automate this process. Fortunately, the day finally came where I found myself with 15 minute s of free time and this issue in my mind.
Here is the scenario. You have a small business and you want to store your customers, products and sales information on separate Google sheets.
You’re probably going to have someone from your staff enter new customers, products are sales transactions.
We know if we get them to enter unique ID’s in manually that mistakes are going to get made. So how about we automate this process with unique ID’s based on date-timestamps.
Why use a date-timestamp to create a unique ID?
Every year is unique. Every day, hour, minute, second and millisecond of that year creates a unique number. This mean that a new unique id will be create every millisecond for us.
Wow! Wow! Wow! Yagi! Just hold it one damn minute! You could have multiple results each millisecond that would each be the same number!
Well, true if we were running a loop generating and publishnig our date-timestamp, we could have multiple numbers. However, we are generating this unique ID as an onEdit function when the user adds some information in Google Sheets to a cell and an adjacent cell returns our unique number.
The user’s input and then the calls to and from the server to the Google Sheet will be sufficiently slow enough not to have a number generated multiple times a millisecond, so we are safe there.
We have the main idea of what we are planning, let’s move onto the example.