You are on page 1of 3

Sub first_macro()

MsgBox "Rajagiri"

End Sub

Sub first_macro()
MsgBox 100

End Sub

Sub cell_refernce()

ActiveCell.Value = "Rajagiri"
ActiveCell.Value = 40

End Sub

Sub cellref()
[F20].Value = 70
End Sub

Sub cellref()
[C2:C10].Value = "Rajagiri"
End Sub

Sub cellref()

Range("d2:d20") = "India"

End Sub

'This code will unmerge all the merged cells


Sub UnmergeAllCells()
ActiveSheet.Cells.UnMerge
End Sub

This code will convert all formulas into values


Sub ConvertToValues()
With ActiveSheet.UsedRange
.Value = .Value
End With
End Sub
Sub AddSerialNumbers()
Dim i As Integer
On Error GoTo Last
i = InputBox("Enter Value", "Enter Serial Numbers")
For i = 1 To i
ActiveCell.Value = i
ActiveCell.Offset(1, 0).Activate
Next i
Last:Exit Sub
End Sub

Calculator
Sub OpenCalculator()
Application.ActivateMicrosoftApp Index:=0
End Sub

Highlight Cells with Comments

To highlight all the cells with comments use this macro.

Sub highlightCommentCells()
Selection.SpecialCells(xlCellTypeComments).Select
Selection.Style= "Note"
End Sub

Highlight Min Value In The Range

It will check all the selected cells and highlight the cell with the Minimum value.

Sub highlightMinValue()
Dim rng As Range
For Each rng In Selection
If rng = WorksheetFunction.Min(Selection) Then
rng.Style = "Good"
End If
Next rng
End Sub

Insert Multiple Worksheets

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 InsertMultipleSheets()
Dim i As Integer
i = InputBox("Enter number of sheets to insert.", "Enter
Multiple Sheets")
Sheets.Add After:=ActiveSheet, Count:=i
End Sub

Protect Worksheet

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.

Sub ProtectWS()
ActiveSheet.Protect "mypassword", True, True
End Sub

Un-Protect Worksheet

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 UnprotectWS()
ActiveSheet.Unprotect "mypassword"
End Sub

You might also like