Excel Macros for Marketing
Ready-to-use VBA macros to automate repetitive marketing tasks in Excel.
1. Clean URLs from Export
Strips query parameters from URL lists except UTM tags you want to keep.
Sub CleanURLs()
Dim cell As Range
For Each cell In Selection
If cell.Value <> "" Then
Dim parts As Variant
parts = Split(cell.Value, "?")
cell.Value = parts(0)
End If
Next cell
End Sub
2. Merge Campaign Data
Combines rows from multiple sheets into one summary table.
Sub MergeSheets()
Dim ws As Worksheet, dest As Worksheet
Set dest = ThisWorkbook.Sheets("Summary")
For Each ws In ThisWorkbook.Sheets
If ws.Name <> "Summary" Then
ws.UsedRange.Copy dest.Cells(dest.Cells(dest.Rows.Count, 1).End(xlUp).Row + 1, 1)
End If
Next ws
End Sub
3. Format Pivot Table
Applies consistent formatting to all pivot tables in the workbook.
Sub FormatPivots()
Dim pt As PivotTable
For Each pt In ActiveSheet.PivotTables
pt.TableStyle2 = "PivotStyleMedium9"
Next pt
End Sub
How to use: Press Alt+F11 to open the VBA editor, insert a new module, paste the macro, and run it with F5.