Now, let's get into the useful macro examples that can help you automate work and save time.
Here is the code that will automatically save the workbook in the specified folder and add a timestamp whenever it's saved.'This code will Save the File With a Timestamp in its name Sub Save Workbook With Time Stamp()Dim timestamp As Stringtimestamp = Format(Date, "dd-mm-yyyy") & "_" & Format(Time, "hh-ss")This Workbook.
Save As "C: Users Username Desktop Workbook Name" & timestamp End Sub You need to specify the folder location and the file name.
Name If you have a lot of worksheets in a workbook and you want to protect all the sheets, you can use this macro code.
It allows you to specify the password within the code.
In case you are working with a worksheet with merged cells, use the code below to unmerge all the merged cells at one go.
Note that instead of Merge and Center, I recommend using Centre Across Selection option.
If you have a workbook with many worksheets and you want to sort these alphabetically, this macro code can come in really handy.
This could be the case if you have sheet names as years or employee names or product names.'This code will sort the worksheets alphabetically Sub Sort Sheets Tab Name()Application.
A lot of time, you may need to create versions of your work.
These are quite helpful in long projects where you work with a file over time.
I will keep updating this tutorial with more macro examples.