Top 100 Useful Excel Macro Examples
Top 100 Useful Excel Macro Examples
excelchamps.com
42–54 minutes
Macro codes can save you a ton of time. You can automate small
as well as heavy tasks with VBA codes.
And do you know? With the help of macros, you can break all the
limitations of Excel which you think Excel has.
You can use these codes even if you haven't used VBA before
that. But here's the first thing to know:
For example, you can use a code to print only a particular range of
cells just with a single click instead of selecting the range > File
Tab > Print > Print Select > OK Button.
1 of 60 06-Nov-2023, 2:49 PM
Top 100 Useful Excel MACRO CODES Examples [VBA Library] + PDF about:reader?url=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttps%2Fexcelchamps.com%2Fblog%2Fuse...
Before you use these codes, make sure you have your developer
tab on your Excel ribbon to access VB editor. Once you activate
developer tab you can use below steps to paste a VBA code into
VB editor.
Basic Codes
This macro code will help you to automatically add serial numbers
in your Excel sheet which can be helpful for you if you work with
large data.
Sub AddSerialNumbers()
Dim i As Integer
On Error GoTo Last
2 of 60 06-Nov-2023, 2:49 PM
Top 100 Useful Excel MACRO CODES Examples [VBA Library] + PDF about:reader?url=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttps%2Fexcelchamps.com%2Fblog%2Fuse...
To use this code, you need to select the cell from where you want
to start the serial numbers and when you run this it shows you a
message box where you need to enter the highest number for the
serial numbers and click OK.
And once you click OK, it simply runs a loop and add a list of serial
numbers to the cells downward.
Sub InsertMultipleColumns()
Dim i As Integer
Dim j As Integer
ActiveCell.EntireColumn.Select
On Error GoTo Last
i = InputBox("Enter number of columns to insert", "Insert
Columns")
For j = 1 To i
Selection.Insert Shift:=xlToRight,
CopyOrigin:=xlFormatFromRightorAbove
Next j
Last: Exit Sub
3 of 60 06-Nov-2023, 2:49 PM
Top 100 Useful Excel MACRO CODES Examples [VBA Library] + PDF about:reader?url=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttps%2Fexcelchamps.com%2Fblog%2Fuse...
End Sub
When you run this code, it asks you the number columns you want
to add and when you click OK, it adds entered number of columns
after the selected cell. If you want to add columns before the
selected cell, replace the xlToRight to xlToLeft in the code.
With this code, you can enter multiple rows in the worksheet.
When you run this code, you can enter the number of rows to
insert and make sure to select the cell from where you want to
insert the new rows.
Sub InsertMultipleRows()
Dim i As Integer
Dim j As Integer
ActiveCell.EntireRow.Select
On Error GoTo Last
i = InputBox("Enter number of columns to insert", "Insert
Columns")
For j = 1 To i
Selection.Insert Shift:=xlToDown,
CopyOrigin:=xlFormatFromRightorAbove
Next j
Last: Exit Sub
End Sub
If you want to add rows before the selected cell, replace the
xlToDown to xlToUp in the code.
4 of 60 06-Nov-2023, 2:49 PM
Top 100 Useful Excel MACRO CODES Examples [VBA Library] + PDF about:reader?url=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttps%2Fexcelchamps.com%2Fblog%2Fuse...
This code quickly auto fits all the columns in your worksheet.
Sub AutoFitColumns()
Cells.Select
Cells.EntireColumn.AutoFit
End Sub
When you run this code, it will select all the cells in your worksheet
and instantly auto-fit all the columns.
You can use this code to auto fit all the rows in a worksheet.
Sub AutoFitRows()
Cells.Select
Cells.EntireRow.AutoFit
End Sub
When you run this code, it will select all the cells in your worksheet
and instantly auto fit all the rows.
This code will help you to remove text wrap from the entire
worksheet with a single click.
Sub RemoveTextWrap()
Range("A1").WrapText = False
End Sub
It will first select all the columns and then remove text wrap and
auto fit all the rows and columns. There’s also a shortcut that you
can use (Alt + H +W) for but if you add this code to Quick Access
5 of 60 06-Nov-2023, 2:49 PM
Top 100 Useful Excel MACRO CODES Examples [VBA Library] + PDF about:reader?url=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttps%2Fexcelchamps.com%2Fblog%2Fuse...
7. Unmerge Cells
This code simply uses the unmerge options which you have on the
HOME tab.
Sub UnmergeCells()
Selection.UnMerge
End Sub
The benefit of using this code is you can add it to the QAT and
unmerge all the cell in the selection. And if you want to un-merge a
specific range you can define that range in the code by replacing
the word selection.
8. Open Calculator
Sub OpenCalculator()
Application.ActivateMicrosoftApp Index:=0
End Sub
As I mentioned that it’s for windows and if you run this code in the
MAC version of VBA you’ll get an error.
This macro adds a date to the header when you run it. It simply
uses the tag "&D" for adding the date.
Sub DateInHeader()
6 of 60 06-Nov-2023, 2:49 PM
Top 100 Useful Excel MACRO CODES Examples [VBA Library] + PDF about:reader?url=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttps%2Fexcelchamps.com%2Fblog%2Fuse...
With ActiveSheet.PageSetup
.LeftHeader = ""
.CenterHeader = "&D"
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = ""
End With
End Sub
Sub CustomHeader()
Dim myText As String
myText = InputBox("Enter your text here", "Enter Text")
With ActiveSheet.PageSetup
.LeftHeader = ""
.CenterHeader = myText
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = ""
End With
End Sub
When you run this code, it shows an input box that asks you to
7 of 60 06-Nov-2023, 2:49 PM
Top 100 Useful Excel MACRO CODES Examples [VBA Library] + PDF about:reader?url=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttps%2Fexcelchamps.com%2Fblog%2Fuse...
enter the text which you want to add as a header, and once you
enter it click OK.
If you see this closely you have six different lines of code to
choose the place for the header or footer. Let’s say if you want to
add left-footer instead of center header simply replace the
“myText” to that line of the code by replacing the "" from there.
Formatting Codes
These VBA codes will help you to format cells and ranges using
some specific criteria and conditions.
Sub HighlightDuplicateValues()
Dim myRange As Range
Dim myCell As Range
Set myRange = Selection
For Each myCell In myRange
If WorksheetFunction.CountIf(myRange, myCell.Value) > 1 Then
myCell.Interior.ColorIndex = 36
End If
Next myCell
End Sub
This macro will check each cell of your selection and highlight the
duplicate values. You can also change the color from the code.
8 of 60 06-Nov-2023, 2:49 PM
Top 100 Useful Excel MACRO CODES Examples [VBA Library] + PDF about:reader?url=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttps%2Fexcelchamps.com%2Fblog%2Fuse...
Remember that, by applying this macro you will not able to edit the
cell by double click.
Sub TopTen()
Selection.FormatConditions.AddTop10
Selection.FormatConditions(Selection.FormatConditions.Count).S
tFirstPriority
With Selection.FormatConditions(1)
.TopBottom = xlTop10Top
.Rank = 10
9 of 60 06-Nov-2023, 2:49 PM
Top 100 Useful Excel MACRO CODES Examples [VBA Library] + PDF about:reader?url=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttps%2Fexcelchamps.com%2Fblog%2Fuse...
.Percent = False
End With
With Selection.FormatConditions(1).Font
.Color = -16752384
.TintAndShade = 0
End With
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 13561798
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
End Sub
Just select a range and run this macro and it will highlight top 10
values with the green color.
Sub HighlightRanges()
Dim RangeName As Name
Dim HighlightRange As Range
On Error Resume Next
For Each RangeName In ActiveWorkbook.Names
Set HighlightRange = RangeName.RefersToRange
HighlightRange.Interior.ColorIndex = 36
Next RangeName
End Sub
If you are not sure about how many named ranges you have in
your worksheet then you can use this code to highlight all of them.
10 of 60 06-Nov-2023, 2:49 PM
Top 100 Useful Excel MACRO CODES Examples [VBA Library] + PDF about:reader?url=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttps%2Fexcelchamps.com%2Fblog%2Fuse...
Sub HighlightGreaterThanValues()
Dim i As Integer
i = InputBox("Enter Greater Than Value", "Enter Value")
Selection.FormatConditions.Delete
Selection.FormatConditions.Add Type:=xlCellValue, _
Operator:=xlGreater, Formula1:=i
Selection.FormatConditions(Selection.FormatConditions.Count).S
tFirstPriority
With Selection.FormatConditions(1)
.Font.Color = RGB(0, 0, 0)
.Interior.Color = RGB(31, 218, 154)
End With
End Sub
Once you run this code it will ask you for the value from which you
want to highlight all greater values.
Sub HighlightLowerThanValues()
Dim i As Integer
i = InputBox("Enter Lower Than Value", "Enter Value")
Selection.FormatConditions.Delete
Selection.FormatConditions.Add _
Type:=xlCellValue, _
Operator:=xlLower, _
Formula1:=i
Selection.FormatConditions(Selection.FormatConditions.Count).S
tFirstPriority
11 of 60 06-Nov-2023, 2:49 PM
Top 100 Useful Excel MACRO CODES Examples [VBA Library] + PDF about:reader?url=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttps%2Fexcelchamps.com%2Fblog%2Fuse...
With Selection.FormatConditions(1)
.Font.Color = RGB(0, 0, 0)
.Interior.Color = RGB(217, 83, 79)
End With
End Sub
Once you run this code it will ask you for the value from which you
want to highlight all lower values.
Sub highlightNegativeNumbers()
Dim Rng As Range
For Each Rng In Selection
If WorksheetFunction.IsNumber(Rng) Then
If Rng.Value < 0 Then
Rng.Font.Color= -16776961
End If
End If
Next
End Sub
Select a range of cells and run this code. It will check each cell
from the range and highlight all cells the where you have a
negative number.
Sub highlightValue()
Dim myStr As String
Dim myRg As range
Dim myTxt As String
12 of 60 06-Nov-2023, 2:49 PM
Top 100 Useful Excel MACRO CODES Examples [VBA Library] + PDF about:reader?url=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttps%2Fexcelchamps.com%2Fblog%2Fuse...
13 of 60 06-Nov-2023, 2:49 PM
Top 100 Useful Excel MACRO CODES Examples [VBA Library] + PDF about:reader?url=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttps%2Fexcelchamps.com%2Fblog%2Fuse...
.Characters(J, Len(myStr)).Font.ColorIndex = 3
Next
End With
Next I
End Sub
Suppose you have a large data set and you want to check for a
particular value. For this, you can use this code. When you run it,
you will get an input box to enter the value to search for.
Sub highlightCommentCells()
Selection.SpecialCells(xlCellTypeComments).Select
Selection.Style= "Note"
End Sub
Sub highlightAlternateRows()
Dim rng As Range
For Each rng In Selection.Rows
If rng.Row Mod 2 = 1 Then
rng.Style = "20% -Accent1"
rng.Value = rng ^ (1 / 3)
Else
End If
Next rng
End Sub
14 of 60 06-Nov-2023, 2:49 PM
Top 100 Useful Excel MACRO CODES Examples [VBA Library] + PDF about:reader?url=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttps%2Fexcelchamps.com%2Fblog%2Fuse...
Sub HighlightMisspelledCells()
Dim rng As Range
For Each rng In ActiveSheet.UsedRange
If Not Application.CheckSpelling(word:=rng.Text) Then
rng.Style = "Bad"
End If
Next rng
End Sub
If you find hard to check all the cells for spelling error then this
code is for you. It will check each cell from the selection and
highlight the cell where is a misspelled word.
Sub highlightErrors()
Dim rng As Range
Dim i As Integer
For Each rng In ActiveSheet.UsedRange
If WorksheetFunction.IsError(rng) Then
i=i+1
rng.Style = "bad"
End If
Next rng
MsgBox _
15 of 60 06-Nov-2023, 2:49 PM
Top 100 Useful Excel MACRO CODES Examples [VBA Library] + PDF about:reader?url=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttps%2Fexcelchamps.com%2Fblog%2Fuse...
To highlight and count all the cells in which you have an error, this
code will help you. Just run this code and it will return a message
with the number error cells and highlight all the cells.
Sub highlightSpecificValues()
Dim rng As range
Dim i As Integer
Dim c As Variant
c = InputBox("Enter Value To Highlight")
For Each rng In ActiveSheet.UsedRange
If rng = c Then
rng.Style = "Note"
i=i+1
End If
Next rng
MsgBox "There are total " & i & " " & c & " in this worksheet."
End Sub
This code will help you to count the cells which have a specific
value which you will mention and after that highlight all those cells.
Sub blankWithSpace()
Dim rng As Range
For Each rng In ActiveSheet.UsedRange
16 of 60 06-Nov-2023, 2:49 PM
Top 100 Useful Excel MACRO CODES Examples [VBA Library] + PDF about:reader?url=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttps%2Fexcelchamps.com%2Fblog%2Fuse...
Sometimes there are some cells which are blank but they have a
single space and due to this, it’s really hard to identify them. This
code will check all the cell in the worksheet and highlight all the
cells which have a single space.
Sub highlightMaxValue()
Dim rng As Range
For Each rng In Selection
If rng = WorksheetFunction.Max(Selection) Then
rng.Style = "Good"
End If
Next rng
End Sub
It will check all the selected cells and highlight the cell with the
maximum value.
Sub Highlight_Min_Value()
17 of 60 06-Nov-2023, 2:49 PM
Top 100 Useful Excel MACRO CODES Examples [VBA Library] + PDF about:reader?url=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttps%2Fexcelchamps.com%2Fblog%2Fuse...
End Sub
It will check all the selected cells and highlight the cell with the
Minimum value.
Sub highlightUniqueValues()
Dim rng As Range
Set rng = Selection
rng.FormatConditions.Delete
Dim uv As UniqueValues
Set uv = rng.FormatConditions.AddUniqueValues
uv.DupeUnique = xlUnique
uv.Interior.Color = vbGreen
End Sub
This codes will highlight all the cells from the selection which has a
unique value.
Sub columnDifference()
Range("H7:H8,I7:I8").Select
Selection.ColumnDifferences(ActiveCell).Select
Selection.Style= "Bad"
End Sub
18 of 60 06-Nov-2023, 2:49 PM
Top 100 Useful Excel MACRO CODES Examples [VBA Library] + PDF about:reader?url=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttps%2Fexcelchamps.com%2Fblog%2Fuse...
Using this code you can highlight the difference between two
columns (corresponding cells).
Sub rowDifference()
Range("H7:H8,I7:I8").Select
Selection.RowDifferences(ActiveCell).Select
Selection.Style= "Bad"
End Sub
And by using this code you can highlight difference between two
row (corresponding cells).
Printing Codes
Sub printComments()
With ActiveSheet.PageSetup
.printComments = xlPrintSheetEnd
End With
End Sub
Sub printNarrowMargin()
With ActiveSheet.PageSetup
19 of 60 06-Nov-2023, 2:49 PM
Top 100 Useful Excel MACRO CODES Examples [VBA Library] + PDF about:reader?url=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttps%2Fexcelchamps.com%2Fblog%2Fuse...
.LeftMargin = Application
.InchesToPoints (0.25)
.RightMargin = Application.InchesToPoints(0.25)
.TopMargin = Application.InchesToPoints(0.75)
.BottomMargin = Application.InchesToPoints(0.75)
.HeaderMargin = Application.InchesToPoints(0.3)
.FooterMargin = Application.InchesToPoints(0.3)
End With
ActiveWindow.SelectedSheets.PrintOut _
Copies:=1, _
Collate:=True, _
IgnorePrintAreas:=False
End Sub
Use this VBA code to take a print with a narrow margin. When you
run this macro it will automatically change margins to narrow.
Sub printSelection()
Selection.PrintOut Copies:=1, Collate:=True
End Sub
This code will help you print selected range. You don't need to go
to printing options and set printing range. Just select a range and
run this code.
Sub printCustomSelection()
Dim startpage As Integer
Dim endpage As Integer
20 of 60 06-Nov-2023, 2:49 PM
Top 100 Useful Excel MACRO CODES Examples [VBA Library] + PDF about:reader?url=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttps%2Fexcelchamps.com%2Fblog%2Fuse...
startpage = _
InputBox("Please Enter Start Page number.", "Enter Value")
If Not WorksheetFunction.IsNumber(startpage) Then
MsgBox _
"Invalid Start Page number. Please try again.", "Error"
Exit Sub
End If
endpage = _
InputBox("Please Enter End Page number.", "Enter Value")
If Not WorksheetFunction.IsNumber(endpage) Then
MsgBox _
"Invalid End Page number. Please try again.", "Error"
Exit Sub
End If
Selection.PrintOut From:=startpage, _
To:=endpage, Copies:=1, Collate:=True
End Sub
Instead of using the setting from print options you can use this
code to print custom page range. Let’s say you want to print pages
from 5 to 10. You just need to run this VBA code and enter start
page and end page.
Worksheet Codes
Sub HideWorksheet()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
If ws.Name <> ThisWorkbook.ActiveSheet.Name Then
21 of 60 06-Nov-2023, 2:49 PM
Top 100 Useful Excel MACRO CODES Examples [VBA Library] + PDF about:reader?url=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttps%2Fexcelchamps.com%2Fblog%2Fuse...
ws.Visible = xlSheetHidden
End If
Next ws
End Sub
Now, let's say if you want to hide all the worksheets in your
workbook other than the active worksheet. This macro code will do
this for you.
Sub UnhideAllWorksheet()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.Visible = xlSheetVisible
Next ws
End Sub
And if you want to un-hide all the worksheets which you have hide
with previous code, here is the code for that.
Sub DeleteWorksheets()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
If ws.name <> ThisWorkbook.ActiveSheet.name Then
Application.DisplayAlerts = False
ws.Delete
Application.DisplayAlerts = True
End If
Next ws
22 of 60 06-Nov-2023, 2:49 PM
Top 100 Useful Excel MACRO CODES Examples [VBA Library] + PDF about:reader?url=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttps%2Fexcelchamps.com%2Fblog%2Fuse...
End Sub
If you want to delete all the worksheets other than the active sheet,
this macro is useful for you. When you run this macro it will
compare the name of the active worksheet with other worksheets
and then delete them.
Sub ProtectAllWorskeets()
Dim ws As Worksheet
Dim ps As String
ps = InputBox("Enter a Password.", vbOKCancel)
For Each ws In ActiveWorkbook.Worksheets
ws.Protect Password:=ps
Next ws
End Sub
Sub Resize_Charts()
Dim i As Integer
For i = 1 To ActiveSheet.ChartObjects.Count
With ActiveSheet.ChartObjects(i)
.Width = 300
.Height = 200
End With
23 of 60 06-Nov-2023, 2:49 PM
Top 100 Useful Excel MACRO CODES Examples [VBA Library] + PDF about:reader?url=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttps%2Fexcelchamps.com%2Fblog%2Fuse...
Next i
End Sub
Make all chart same in size. This macro code will help you to make
all the charts of the same size. You can change the height and
width of charts by changing it in macro code.
Sub InsertMultipleSheets()
Dim i As Integer
i=_
InputBox("Enter number of sheets to insert.", _
"Enter Multiple Sheets")
Sheets.Add After:=ActiveSheet, Count:=i
End Sub
You can use this code if you want to add multiple worksheets in
your workbook in a single shot. When you run this macro code you
will get an input box to enter the total number of sheets you want
to enter.
Sub ProtectWS()
ActiveSheet.Protect "mypassword", True, True
End Sub
If you want to protect your worksheet you can use this macro
code. All you have to do just mention your password in the code.
24 of 60 06-Nov-2023, 2:49 PM
Top 100 Useful Excel MACRO CODES Examples [VBA Library] + PDF about:reader?url=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttps%2Fexcelchamps.com%2Fblog%2Fuse...
Sub UnprotectWS()
ActiveSheet.Unprotect "mypassword"
End Sub
If you want to unprotect your worksheet you can use this macro
code. All you have to do just mention your password which you
have used while protecting your worksheet.
Sub SortWorksheets()
Dim i As Integer
Dim j As Integer
Dim iAnswer As VbMsgBoxResult
iAnswer = MsgBox("Sort Sheets in Ascending Order?" & Chr(10) _
& "Clicking No will sort in Descending Order", _
vbYesNoCancel + vbQuestion + vbDefaultButton1, "Sort
Worksheets")
For i = 1 To Sheets.Count
For j = 1 To Sheets.Count - 1
If iAnswer = vbYes Then
If UCase$(Sheets(j).Name) > UCase$(Sheets(j + 1).Name) Then
Sheets(j).Move After:=Sheets(j + 1)
End If
ElseIf iAnswer = vbNo Then
If UCase$(Sheets(j).Name) < UCase$(Sheets(j + 1).Name) Then
Sheets(j).Move After:=Sheets(j + 1)
End If
End If
Next j
Next i
25 of 60 06-Nov-2023, 2:49 PM
Top 100 Useful Excel MACRO CODES Examples [VBA Library] + PDF about:reader?url=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttps%2Fexcelchamps.com%2Fblog%2Fuse...
End Sub
Sub lockCellsWithFormulas()
With ActiveSheet
.Unprotect
.Cells.Locked = False
.Cells.SpecialCells(xlCellTypeFormulas).Locked = True
.Protect AllowDeletingRows:=True
End With
End Sub
To protect cell with formula with a single click you can use this
code.
Sub deleteBlankWorksheets()
Dim Ws As Worksheet
On Error Resume Next
Application.ScreenUpdating= False
Application.DisplayAlerts= False
For Each Ws In Application.Worksheets
If Application.WorksheetFunction.CountA(Ws.UsedRange) = 0
Then
Ws.Delete
End If
Next
26 of 60 06-Nov-2023, 2:49 PM
Top 100 Useful Excel MACRO CODES Examples [VBA Library] + PDF about:reader?url=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttps%2Fexcelchamps.com%2Fblog%2Fuse...
Application.ScreenUpdating= True
Application.DisplayAlerts= True
End Sub
Run this code and it will check all the worksheets in the active
workbook and delete if a worksheet is blank.
Sub UnhideRowsColumns()
Columns.EntireColumn.Hidden = False
Rows.EntireRow.Hidden = False
End Sub
Sub SaveWorkshetAsPDF()
Dimws As Worksheet
For Each ws In Worksheets
ws.ExportAsFixedFormat _
xlTypePDF, _
"ENTER-FOLDER-NAME-HERE" & _
ws.Name & ".pdf"
Next ws
End Sub
This code will simply save all the worksheets in a separate PDF
file. You just need to change the folder name from the code.
27 of 60 06-Nov-2023, 2:49 PM
Top 100 Useful Excel MACRO CODES Examples [VBA Library] + PDF about:reader?url=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttps%2Fexcelchamps.com%2Fblog%2Fuse...
Sub DisablePageBreaks()
Dim wb As Workbook
Dim wks As Worksheet
Application.ScreenUpdating = False
For Each wb In Application.Workbooks
For Each Sht In wb.Worksheets
Sht.DisplayPageBreaks = False
Next Sht
Next wb
Application.ScreenUpdating = True
End Sub
To disable page breaks use this code. It will simply disable page
breaks from all the open workbooks.
Workbook Codes
Sub FileBackUp()
ThisWorkbook.SaveCopyAs Filename:=ThisWorkbook.Path & _
"" & Format(Date, "mm-dd-yy") & " " & _
ThisWorkbook.name
End Sub
This is one of the most useful macros which can help you to save
a backup file of your current workbook.
28 of 60 06-Nov-2023, 2:49 PM
Top 100 Useful Excel MACRO CODES Examples [VBA Library] + PDF about:reader?url=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttps%2Fexcelchamps.com%2Fblog%2Fuse...
It will save a backup file in the same directory where your current
file is saved and it will also add the current date with the name of
the file.
Sub CloseAllWorkbooks()
Dim wbs As Workbook
For Each wbs In Workbooks
wbs.Close SaveChanges:=True
Next wb
End Sub
Use this macro code to close all open workbooks. This macro
code will first check all the workbooks one by one and close them.
If any of the worksheets is not saved, you'll get a message to save
it.
Sub CopyWorksheetToNewWorkbook()
ThisWorkbook.ActiveSheet.Copy _
Before:=Workbooks.Add.Worksheets(1)
End Sub
Sub Send_Mail()
29 of 60 06-Nov-2023, 2:49 PM
Top 100 Useful Excel MACRO CODES Examples [VBA Library] + PDF about:reader?url=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttps%2Fexcelchamps.com%2Fblog%2Fuse...
Sub OpenWorkbookAsAttachment()
Application.Dialogs(xlDialogSendMail).Show
End Sub
Once you run this macro it will open your default mail client and
attached active workbook with it as an attachment.
Sub auto_open()
30 of 60 06-Nov-2023, 2:49 PM
Top 100 Useful Excel MACRO CODES Examples [VBA Library] + PDF about:reader?url=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttps%2Fexcelchamps.com%2Fblog%2Fuse...
MsgBox _
"Welcome To ExcelChamps & Thanks for downloading this file."
End Sub
You can use auto_open to perform a task on opening a file and all
you have to do just name your macro "auto_open".
Sub auto_close()
MsgBox "Bye Bye! Don't forget to check other cool stuff on
excelchamps.com"
End Sub
You can use close_open to perform a task on opening a file and all
you have to do just name your macro "close_open".
Sub VisibleWorkbooks()
Dim book As Workbook
Dim i As Integer
For Each book In Workbooks
If book.Saved = False Then
i=i+1
End If
Next book
MsgBox i
End Sub
Let’s you have 5-10 open workbooks, you can use this code to get
the number of workbooks which are not saved yet.
31 of 60 06-Nov-2023, 2:49 PM
Top 100 Useful Excel MACRO CODES Examples [VBA Library] + PDF about:reader?url=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttps%2Fexcelchamps.com%2Fblog%2Fuse...
Sub HideSubtotals()
Dim pt As PivotTable
Dim pf As PivotField
On Error Resume Next
Set pt = ActiveSheet.PivotTables(ActiveCell.PivotTable.Name)
If pt Is Nothing Then
MsgBox "You must place your cursor inside of a PivotTable."
Exit Sub
End If
For Each pf In pt.PivotFields
pf.Subtotals(1) = True
pf.Subtotals(1) = False
Next pf
End Sub
If you want to hide all the subtotals, just run this code. First of all,
make sure to select a cell from your pivot table and then run this
macro.
Sub vba_referesh_all_pivots()
Dim pt As PivotTable
For Each pt In ActiveWorkbook.PivotTables
pt.RefreshTable
Next pt
End Sub
32 of 60 06-Nov-2023, 2:49 PM
Top 100 Useful Excel MACRO CODES Examples [VBA Library] + PDF about:reader?url=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttps%2Fexcelchamps.com%2Fblog%2Fuse...
A super quick method to refresh all pivot tables. Just run this code
and all of your pivot tables in your workbook will be refresh in a
single shot.
Sub UpdatePivotTableRange()
Dim Data_Sheet As Worksheet
Dim Pivot_Sheet As Worksheet
Dim StartPoint As Range
Dim DataRange As Range
Dim PivotName As String
Dim NewRange As String
Dim LastCol As Long
Dim lastRow As Long
'Set Pivot Table & Source Worksheet
Set Data_Sheet = ThisWorkbook.Worksheets("PivotTableData3")
Set Pivot_Sheet = ThisWorkbook.Worksheets("Pivot3")
'Enter in Pivot Table Name
PivotName = "PivotTable2"
'Defining Staring Point & Dynamic Range
Data_Sheet.Activate
Set StartPoint = Data_Sheet.Range("A1")
LastCol = StartPoint.End(xlToRight).Column
DownCell = StartPoint.End(xlDown).Row
Set DataRange = Data_Sheet.Range(StartPoint, Cells(DownCell,
33 of 60 06-Nov-2023, 2:49 PM
Top 100 Useful Excel MACRO CODES Examples [VBA Library] + PDF about:reader?url=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttps%2Fexcelchamps.com%2Fblog%2Fuse...
LastCol))
NewRange = Data_Sheet.Name & "!" &
DataRange.Address(ReferenceStyle:=xlR1C1)
'Change Pivot Table Data Source Range Address
Pivot_Sheet.PivotTables(PivotName). _
ChangePivotCache ActiveWorkbook. _
PivotCaches.Create(SourceType:=xlDatabase,
SourceData:=NewRange)
'Ensure Pivot Table is Refreshed
Pivot_Sheet.PivotTables(PivotName).RefreshTable
'Complete Message
Pivot_Sheet.Activate
MsgBox "Your Pivot Table is now updated."
End Sub
If you are not using Excel tables then you can use this code to
update pivot table range.
Sub activateGetPivotData()
Application.GenerateGetPivotData = True
End Sub
Sub deactivateGetPivotData()
Application.GenerateGetPivotData = False
End Sub
Charts Codes
34 of 60 06-Nov-2023, 2:49 PM
Top 100 Useful Excel MACRO CODES Examples [VBA Library] + PDF about:reader?url=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttps%2Fexcelchamps.com%2Fblog%2Fuse...
Sub ChangeChartType()
ActiveChart.ChartType = xlColumnClustered
End Sub
This code will help you to convert chart type without using chart
options from the tab. All you have to do just specify to which type
you want to convert.
Sub ConvertChartToPicture()
ActiveChart.ChartArea.Copy
ActiveSheet.Range("A1").Select
ActiveSheet.Pictures.Paste.Select
End Sub
This code will help you to convert your chart into an image. You
just need to select your chart and run this code.
Sub AddChartTitle()
Dim i As Variant
i = InputBox("Please enter your chart title", "Chart Title")
On Error GoTo Last
ActiveChart.SetElement (msoElementChartTitleAboveChart)
35 of 60 06-Nov-2023, 2:49 PM
Top 100 Useful Excel MACRO CODES Examples [VBA Library] + PDF about:reader?url=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttps%2Fexcelchamps.com%2Fblog%2Fuse...
ActiveChart.ChartTitle.Text = i
Last:
Exit Sub
End Sub
First of all, you need to select your chart and the run this code. You
will get an input box to enter chart title.
Advanced Codes
Sub HideSubtotals()
Dim pt As PivotTable
Dim pf As PivotField
On Error Resume Next
Set pt = ActiveSheet.PivotTables(ActiveCell.PivotTable.name)
If pt Is Nothing Then
MsgBox "You must place your cursor inside of a PivotTable."
Exit Sub
End If
For Each pf In pt.PivotFields
pf.Subtotals(1) = True
pf.Subtotals(1) = False
Next pf
End Sub
If you want to hide all the subtotals, just run this code. First of all,
make sure to select a cell from your pivot table and then run this
macro.
36 of 60 06-Nov-2023, 2:49 PM
Top 100 Useful Excel MACRO CODES Examples [VBA Library] + PDF about:reader?url=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttps%2Fexcelchamps.com%2Fblog%2Fuse...
Sub TableofContent()
Dim i As Long
On Error Resume Next
Application.DisplayAlerts = False
Worksheets("Table of Content").Delete
Application.DisplayAlerts = True
On Error GoTo 0
ThisWorkbook.Sheets.Add Before:=ThisWorkbook.Worksheets(1)
ActiveSheet.Name = "Table of Content"
For i = 1 To Sheets.Count
With ActiveSheet
.Hyperlinks.Add _
Anchor:=ActiveSheet.Cells(i, 1), _
Address:="", _
SubAddress:="'" & Sheets(i).Name & "'!A1", _
ScreenTip:=Sheets(i).Name, _
TextToDisplay:=Sheets(i).Name
End With
Next i
End Sub
Let's say you have more than 100 worksheets in your workbook
and it's hard to navigate now.
Don't worry this macro code will rescue everything. When you run
this code it will create a new worksheet and create a index of
worksheets with a hyperlink to them.
Sub PasteAsPicture()
37 of 60 06-Nov-2023, 2:49 PM
Top 100 Useful Excel MACRO CODES Examples [VBA Library] + PDF about:reader?url=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttps%2Fexcelchamps.com%2Fblog%2Fuse...
Application.CutCopyMode = False
Selection.Copy
ActiveSheet.Pictures.Paste.Select
End Sub
Sub LinkedPicture()
Selection.Copy
ActiveSheet.Pictures.Paste(Link:=True).Select
End Sub
This VBA code will convert your selected range into a linked
picture and you can use that image anywhere you want.
Sub Speak()
Selection.Speak
End Sub
Just select a range and run this code. Excel will speak all the text
what you have in that range, cell by cell.
Sub DataForm()
ActiveSheet.ShowDataForm
End Sub
38 of 60 06-Nov-2023, 2:49 PM
Top 100 Useful Excel MACRO CODES Examples [VBA Library] + PDF about:reader?url=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttps%2Fexcelchamps.com%2Fblog%2Fuse...
There is a default data entry form which you can use for data entry.
Sub GoalSeekVBA()
Dim Target As Long
On Error GoTo Errorhandler
Target = InputBox("Enter the required value", "Enter Value")
Worksheets("Goal_Seek").Activate
With ActiveSheet.Range("C7")
.GoalSeek_ Goal:=Target, _
ChangingCell:=Range("C2")
End With
Exit Sub
Errorhandler: MsgBox ("Sorry, value is not valid.")
End Sub
Sub SearchWindow32()
Dim chromePath As String
Dim search_string As String
Dim query As String
query = InputBox("Enter here your search here", "Google Search")
search_string = query
search_string = Replace(search_string, " ", "+")
'Uncomment the following line for Windows 64 versions and
39 of 60 06-Nov-2023, 2:49 PM
Top 100 Useful Excel MACRO CODES Examples [VBA Library] + PDF about:reader?url=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttps%2Fexcelchamps.com%2Fblog%2Fuse...
Formula Codes
Sub convertToValues()
Dim MyRange As Range
Dim MyCell As Range
Select Case _
MsgBox("You Can't Undo This Action. " _
& "Save Workbook First?", vbYesNoCancel, _
"Alert")
Case Is = vbYes
ThisWorkbook.Save
Case Is = vbCancel
Exit Sub
End Select
Set MyRange = Selection
For Each MyCell In MyRange
If MyCell.HasFormula Then
MyCell.Formula = MyCell.Value
40 of 60 06-Nov-2023, 2:49 PM
Top 100 Useful Excel MACRO CODES Examples [VBA Library] + PDF about:reader?url=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttps%2Fexcelchamps.com%2Fblog%2Fuse...
End If
Next MyCell
End Sub
Simply convert formulas into values. When you run this macro it
will quickly change the formulas into absolute values.
Sub RemoveSpaces()
Dim myRange As Range
Dim myCell As Range
Select Case MsgBox("You Can't Undo This Action. " _
& "Save Workbook First?", _
vbYesNoCancel, "Alert")
Case Is = vbYesThisWorkbook.Save
Case Is = vbCancel
Exit Sub
End Select
Set myRange = Selection
For Each myCell In myRange
If Not IsEmpty(myCell) Then
myCell = Trim(myCell)
End If
Next myCell
End Sub
One of the most useful macros from this list. It will check your
selection and then remove all the extra spaces from that.
41 of 60 06-Nov-2023, 2:49 PM
Top 100 Useful Excel MACRO CODES Examples [VBA Library] + PDF about:reader?url=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttps%2Fexcelchamps.com%2Fblog%2Fuse...
Simply remove characters from the starting of a text string. All you
need is to refer to a cell or insert a text into the function and
number of characters to remove from the text string.
It has two arguments "rng" for the text string and "cnt" for the count
of characters to remove. For Example: If you want to remove first
characters from a cell, you need to enter 1 in cnt.
Sub degreeSymbol( )
Dim rng As Range
For Each rng In Selection
rng.Select
If ActiveCell <> "" Then
If IsNumeric(ActiveCell.Value) Then
ActiveCell.Value = ActiveCell.Value & "°"
End If
End If
Next
End Sub
Let’s say you have a list of numbers in a column and you want to
add degree symbol with all of them.
42 of 60 06-Nov-2023, 2:49 PM
Top 100 Useful Excel MACRO CODES Examples [VBA Library] + PDF about:reader?url=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttps%2Fexcelchamps.com%2Fblog%2Fuse...
rvrse = VBA.strReverse(cell.Value)
End Function
All you have to do just enter "rvrse" function in a cell and refer to
the cell in which you have text which you want to reverse.
Sub ActivateR1C1()
If Application.ReferenceStyle = xlA1 Then
Application.ReferenceStyle = xlR1C1
Else
Application.ReferenceStyle = xlR1C1
End If
End Sub
This macro code will help you to activate R1C1 reference style
without using Excel options.
Sub ActivateA1()
If Application.ReferenceStyle = xlR1C1 Then
Application.ReferenceStyle = xlA1
Else
Application.ReferenceStyle = xlA1
End If
End Sub
43 of 60 06-Nov-2023, 2:49 PM
Top 100 Useful Excel MACRO CODES Examples [VBA Library] + PDF about:reader?url=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttps%2Fexcelchamps.com%2Fblog%2Fuse...
Sub TimeStamp()
Dim i As Integer
For i = 1 To 24
ActiveCell.FormulaR1C1 = i & ":00"
ActiveCell.NumberFormat = "[$-409]h:mm AM/PM;@"
ActiveCell.Offset(RowOffset:=1, ColumnOffset:=0).Select
Next i
End Sub
With this code, you can insert a time range in sequence from
00:00 to 23:00.
Sub date2day()
Dim tempCell As Range
Selection.Value = Selection.Value
For Each tempCell In Selection
If IsDate(tempCell) = True Then
With tempCell
.Value = Day(tempCell)
.NumberFormat = "0"
End With
End If
Next tempCell
End Sub
If you have dates in your worksheet and you want to convert all
those dates into days then this code is for you. Simply select the
44 of 60 06-Nov-2023, 2:49 PM
Top 100 Useful Excel MACRO CODES Examples [VBA Library] + PDF about:reader?url=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttps%2Fexcelchamps.com%2Fblog%2Fuse...
Sub date2year()
Dim tempCell As Range
Selection.Value = Selection.Value
For Each tempCell In Selection
If IsDate(tempCell) = True Then
With tempCell
.Value = Year(tempCell)
.NumberFormat = "0"
End With
End If
Next tempCell
End Sub
Sub removeTime()
Dim Rng As Range
For Each Rng In Selection
If IsDate(Rng) = True Then
Rng.Value = VBA.Int(Rng.Value)
End If
Next
Selection.NumberFormat = "dd-mmm-yy"
End Sub
If you have time with the date and you want to remove it then you
45 of 60 06-Nov-2023, 2:49 PM
Top 100 Useful Excel MACRO CODES Examples [VBA Library] + PDF about:reader?url=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttps%2Fexcelchamps.com%2Fblog%2Fuse...
Sub removeDate()
Dim Rng As Range
For Each Rng In Selection
If IsDate(Rng) = True Then
Rng.Value = Rng.Value - VBA.Fix(Rng.Value)
End If
NextSelection.NumberFormat = "hh:mm:ss am/pm"
End Sub
Sub convertUpperCase()
Dim Rng As Range
For Each Rng In Selection
If Application.WorksheetFunction.IsText(Rng) Then
Rng.Value = UCase(Rng)
End If
Next
End Sub
Select the cells and run this code. It will check each and every cell
of selected range and then convert it into upper case text.
Sub convertLowerCase()
46 of 60 06-Nov-2023, 2:49 PM
Top 100 Useful Excel MACRO CODES Examples [VBA Library] + PDF about:reader?url=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttps%2Fexcelchamps.com%2Fblog%2Fuse...
This code will help you to convert selected text into lower case
text. Just select a range of cells where you have text and run this
code. If a cell has a number or any value other than text that value
will remain same.
Sub convertProperCase()
Dim Rng As Range
For Each Rng In Selection
If WorksheetFunction.IsText(Rng) Then
Rng.Value = WorksheetFunction.Proper(Rng.Value)
End If
Next
End Sub
And this code will convert selected text into the proper case where
you have the first letter in capital and rest in small.
Sub convertTextCase()
Dim Rng As Range
For Each Rng In Selection
47 of 60 06-Nov-2023, 2:49 PM
Top 100 Useful Excel MACRO CODES Examples [VBA Library] + PDF about:reader?url=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttps%2Fexcelchamps.com%2Fblog%2Fuse...
If WorksheetFunction.IsText(Rng) Then
Rng.Value = UCase(Left(Rng, 1)) & LCase(Right(Rng, Len(Rng) -
1))
End If
Next Rng
End Sub
In text case, you have the first letter of the first word in capital and
rest all in words in small for a single sentence and this code will
help you convert normal text into sentence case.
Sub removeChar()
Dim Rng As Range
Dim rc As String
rc = InputBox("Character(s) to Replace", "Enter Value")
For Each Rng In Selection
Selection.Replace What:=rc, Replacement:=""
Next
End Sub
Sub Word_Count_Worksheet()
Dim WordCnt As Long
Dim rng As Range
Dim S As String
48 of 60 06-Nov-2023, 2:49 PM
Top 100 Useful Excel MACRO CODES Examples [VBA Library] + PDF about:reader?url=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttps%2Fexcelchamps.com%2Fblog%2Fuse...
Dim N As Long
For Each rng In ActiveSheet.UsedRange.Cells
S = Application.WorksheetFunction.Trim(rng.Text)
N=0
If S <> vbNullString Then
N = Len(S) - Len(Replace(S, " ", "")) + 1
End If
WordCnt = WordCnt + N
Next rng
MsgBox "There are total " _
& Format(WordCnt, "#,##0") & _
" words in the active worksheet"
End Sub
Sub removeApostrophes()
Selection.Value = Selection.Value
End Sub
Sub removeDecimals()
Dim lnumber As Double
Dim lResult As Long
Dim rng As Range
For Each rng In Selection
49 of 60 06-Nov-2023, 2:49 PM
Top 100 Useful Excel MACRO CODES Examples [VBA Library] + PDF about:reader?url=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttps%2Fexcelchamps.com%2Fblog%2Fuse...
rng.Value = Int(rng)
rng.NumberFormat = "0"
Next rng
End Sub
This code will simply help you to remove all the decimals from the
numbers from the selected range.
Sub addNumber()
Dim rng As Range
Dim i As Integer
i = InputBox("Enter number to multiple", "Input Required")
For Each rng In Selection
If WorksheetFunction.IsNumber(rng) Then
rng.Value = rng + i
Else
End If
Next rng
End Sub
Let’s you have a list of numbers and you want to multiply all the
number with a particular. To use this code: Select that range of
cells and run this code. It will first ask you for the number with
whom you want to multiple and then instantly multiply all the
numbers with it.
Sub addNumber()
Dim rng As Range
50 of 60 06-Nov-2023, 2:49 PM
Top 100 Useful Excel MACRO CODES Examples [VBA Library] + PDF about:reader?url=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttps%2Fexcelchamps.com%2Fblog%2Fuse...
Dim i As Integer
i = InputBox("Enter number to multiple", "Input Required")
For Each rng In Selection
If WorksheetFunction.IsNumber(rng) Then
rng.Value = rng + i
Else
End If
Next rng
End Sub
Just like multiplying you can also add a number into a set of
numbers.
Sub getSquareRoot()
Dim rng As Range
Dim i As Integer
For Each rng In Selection
If WorksheetFunction.IsNumber(rng) Then
rng.Value = Sqr(rng)
Else
End If
Next rng
End Sub
51 of 60 06-Nov-2023, 2:49 PM
Top 100 Useful Excel MACRO CODES Examples [VBA Library] + PDF about:reader?url=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttps%2Fexcelchamps.com%2Fblog%2Fuse...
Sub getCubeRoot()
Dim rng As Range
Dimi As Integer
For Each rng In Selection
If WorksheetFunction.IsNumber(rng) Then
rng.Value = rng ^ (1 / 3)
Else
End If
Nextrng
End Sub
To calculate cube root without applying a formula you can use this
code. It will simply check all the selected cells and convert
numbers to their cube root.
Sub addsAlphabets1()
Dim i As Integer
For i = 65 To 90
ActiveCell.Value = Chr(i)
ActiveCell.Offset(1, 0).Select
Next i
End Sub
Sub addsAlphabets2()
Dim i As Integer
For i = 97 To 122
ActiveCell.Value = Chr(i)
ActiveCell.Offset(1, 0).Select
Next i
52 of 60 06-Nov-2023, 2:49 PM
Top 100 Useful Excel MACRO CODES Examples [VBA Library] + PDF about:reader?url=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttps%2Fexcelchamps.com%2Fblog%2Fuse...
End Sub
Just like serial numbers you can also insert alphabets in your
worksheet. Beloware the code which you can use.
Sub convertToNumbers()
Dim rng As Range
Selection.Value = Selection.Value
For Each rng In Selection
If Not WorksheetFunction.IsNonText(rng) Then
rng.Value = WorksheetFunction.Arabic(rng)
End If
Next rng
End Sub
Sub removeNegativeSign()
Dim rng As Range
Selection.Value = Selection.Value
For Each rng In Selection
If WorksheetFunction.IsNumber(rng) Then
rng.Value = Abs(rng)
End If
Next rng
53 of 60 06-Nov-2023, 2:49 PM
Top 100 Useful Excel MACRO CODES Examples [VBA Library] + PDF about:reader?url=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttps%2Fexcelchamps.com%2Fblog%2Fuse...
This code will simply check all the cell in the selection and convert
all the negative numbers into positive. Just select a range and run
this code.
Sub replaceBlankWithZero()
Dim rng As Range
Selection.Value = Selection.Value
For Each rng In Selection
If rng = "" Or rng = " " Then
rng.Value = "0"
Else
End If
Next rng
End Sub
For data where you have blank cells, you can use the below code
to add zeros in all those cells. It makes easier to use those cells in
further calculations.
• Add a Line Break in a VBA Code (Single Line into Several Lines)
54 of 60 06-Nov-2023, 2:49 PM
Top 100 Useful Excel MACRO CODES Examples [VBA Library] + PDF about:reader?url=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttps%2Fexcelchamps.com%2Fblog%2Fuse...
• VBA Module
• VBA Objects
• VBA With
55 of 60 06-Nov-2023, 2:49 PM
Top 100 Useful Excel MACRO CODES Examples [VBA Library] + PDF about:reader?url=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttps%2Fexcelchamps.com%2Fblog%2Fuse...
56 of 60 06-Nov-2023, 2:49 PM
Top 100 Useful Excel MACRO CODES Examples [VBA Library] + PDF about:reader?url=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttps%2Fexcelchamps.com%2Fblog%2Fuse...
• VBA Constants
• VBA Array
57 of 60 06-Nov-2023, 2:49 PM
Top 100 Useful Excel MACRO CODES Examples [VBA Library] + PDF about:reader?url=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttps%2Fexcelchamps.com%2Fblog%2Fuse...
• MOD in VBA
• Random Number
• VBA Concatenate
• VBA Exit IF
• VBA IF Not
• VBA Nested IF
58 of 60 06-Nov-2023, 2:49 PM
Top 100 Useful Excel MACRO CODES Examples [VBA Library] + PDF about:reader?url=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttps%2Fexcelchamps.com%2Fblog%2Fuse...
• VBA FOR LOOP (For Next, For Each) – The Guide + Examples
• VBA ScreenUpdating
59 of 60 06-Nov-2023, 2:49 PM
Top 100 Useful Excel MACRO CODES Examples [VBA Library] + PDF about:reader?url=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttps%2Fexcelchamps.com%2Fblog%2Fuse...
60 of 60 06-Nov-2023, 2:49 PM