However, that code by macro recorder is often full of code that is not really needed. So it pays to have a collection of useful VBA macro codes that you can have in your back pocket and use it when needed.
While writing an Excel VBA macro code may take some time initially, once it's done, you can keep it available as a reference and use it whenever you need it next.
If you think something should be on the list, just leave a comment. Now before I get into the Macro Example and give you the VBA code, let me first show you how to use these example codes.
These are quite helpful in long projects where you work with a file over time.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.Screen Updating = False Dim Sh Count As Integer, i As Integer, j As Integer Sh Count = Sheets.Count For i = 1 To Sh Count - 1For j = i 1 To Sh Count If Sheets(j).Unprotect password:=password Next ws End Sub It's a common practice to merge cells to make it one.While it does the work, when cells are merged you will not be able to sort the data.A good practice is to save the file with timestamps.Using timestamps will allow you to go back to a certain file to see what changes were made or what data was used.In this massive article, I am going to list some useful Excel macro examples that I need often and keep stashed away in my private vault.I will keep updating this tutorial with more macro examples.