🔥 10 Useful Real-Life Excel VBA Codes You’ll Actually Use (Copy & Paste Ready) Tired of repetitive Excel tasks?
Want to automate your work, clean data faster, and send emails without ever leaving your workbook? You’ve just found the ultimate list of real-world Excel VBA macros. These aren’t just cool tricks — they’re practical, time-saving VBA macros you’ll actually use. Copy, paste, and automate your daily Excel life!
VBA CODE
Vishal Aggarwal
6/28/20253 min read


Want to automate your work, clean data faster, and send emails without ever leaving your workbook?
You’ve just found the ultimate list of real-world Excel VBA macros.
These aren’t just cool tricks — they’re practical, time-saving VBA macros you’ll actually use.
Copy, paste, and automate your daily Excel life!
🛠️ How to Open the VBA Editor in Excel
Press ALT + F11 to open the Visual Basic for Applications (VBA) Editor.
In the left panel (Project Explorer), select the workbook you’re working on.
📦 How to Insert a VBA Module
Click Insert > Module
A blank white window will appear — this is where you’ll paste your macro code.
Press CTRL + S to save your workbook as Excel Macro-Enabled Workbook (.xlsm).
✅ Why Use VBA in Excel?
VBA lets you automate tasks like:
Formatting & data cleanup
Sending daily emails
Saving backups & reports
Adding timestamps or alerts
Even converting ranges into structured tables
Imagine replacing 30 minutes of manual work with a 3-second macro!
Let’s dive in👇
📌 1. Auto-Save Workbook Every X Minutes
Perfect for: Preventing data loss
Private Sub Workbook_Open()
Application.OnTime Now + TimeValue("00:10:00"), "AutoSave"
End Sub
Sub AutoSave()
Application.OnTime Now + TimeValue("00:10:00"), "AutoSave"
End Sub
🔧 How it works: When the file is opened, it will auto-save every 10 minutes.
👉 Pro Tip: Paste Workbook_Open() in ThisWorkbook, and AutoSave in a module.
📌 2. Convert All Sheets’ Ranges to Excel Tables
Perfect for: Making data analysis-ready with structured tables
Sub ConvertAllRangesToTables()
Dim ws As Worksheet
Dim tbl As ListObject
For Each ws In ThisWorkbook.Sheets
If ws.UsedRange.Cells.Count > 1 Then
Set tbl = ws.ListObjects.Add(xlSrcRange, ws.UsedRange, , xlYes)
tbl.Name = "Table_" & ws.Index
End If
Next ws
End Sub
✅ Why this rocks: Converts raw data into Excel Tables across all sheets — instantly enables filters, formulas, and structured references!
📌 3. Send Outlook Email Directly from Excel
Perfect for: Daily reports, client updates, or team summaries
Sub SendEmail()
Dim OutApp As Object
Dim OutMail As Object
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
With OutMail
.To = "client@example.com"
.Subject = "Daily Report"
.Body = "Hi, please find today's report attached."
.Attachments.Add "C:\Users\YourName\Documents\report.xlsx"
.Send
End With
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
💼 Why use this? Automate daily report emailing without opening Outlook!
📌 4. Highlight Duplicate Values Instantly
Perfect for: Data cleaning and validation
Sub HighlightDuplicates()
Dim rng As Range
Set rng = Selection
rng.FormatConditions.AddUniqueValues
With rng.FormatConditions(rng.FormatConditions.Count)
.DupeUnique = xlDuplicate
.Font.Color = RGB(255, 255, 255)
.Interior.Color = RGB(255, 0, 0)
End With
End Sub
🎯 Use case: Select your data → Run macro → Duplicates get highlighted in red.
📌 5. Create a Backup Copy of Your Workbook
Perfect for: Version control & protection
Sub BackupWorkbook()
Dim FilePath As String
FilePath = ThisWorkbook.Path & "\" & _
"Backup_" & Format(Now, "yyyymmdd_hhmmss") & ".xlsm"
ThisWorkbook.SaveCopyAs FilePath
MsgBox "Backup saved at: " & FilePath
End Sub
🛡️ Pro Tip: Run before heavy edits or monthly updates.
📌 6. List All Sheet Names in One Click
Perfect for: Navigating large workbooks
Sub ListAllSheets()
Dim i As Integer
Sheets.Add.Name = "Sheet Index"
For i = 1 To Sheets.Count
Sheets("Sheet Index").Cells(i, 1).Value = Sheets(i).Name
Next i
End Sub
📄 Creates a summary sheet of all worksheet names for easy reference.
📌 7. Delete Blank Rows in a Selected Range
Perfect for: Cleaning imported or messy data
Sub DeleteBlankRows()
Dim Rng As Range
Set Rng = Range("A1:A1000")
For i = Rng.Rows.Count To 1 Step -1
If WorksheetFunction.CountA(Rng.Rows(i)) = 0 Then
Rng.Rows(i).EntireRow.Delete
End If
Next i
End Sub
🧹 Clean empty rows in seconds.
📌 8. Add Timestamp When a Cell Is Updated
Perfect for: Audit trails or data tracking
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A2:A100")) Is Nothing Then
Target.Offset(0, 1).Value = Now
End If
End Sub
🕒 Automatically logs when an entry was made or edited.
📌 9. Generate a PDF Report From Sheet
Perfect for: Sharing clean, printable reports
Sub ExportSheetToPDF()
ActiveSheet.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=ThisWorkbook.Path & "\My_Report.pdf", _
Quality:=xlQualityStandard
End Sub
📤 Makes your reports sharable in just 2 seconds.
📌 10. Reverse a List of Names
Perfect for: Reordering or re-ranking items
Sub ReverseList()
Dim i As Long, j As Long
For i = 2 To 11
j = 13 - i
Cells(i, 2).Value = Cells(j, 1).Value
Next i
End Sub
🔁 Assumes data in A2:A11 → outputs reverse in B2:B11.
🧠 Final Thoughts: Boost Productivity With VBA
You don’t need to be a coder to use VBA — just copy, paste, and save hours.
Start with one macro, assign it to a button or shortcut, and feel the power of automation in Excel.
✅ Build your own productivity tool
✅ Say goodbye to manual errors
✅ Automate Excel the smart way!
Stay Tuned and Happy Learning!