Comprehensive VBA Notes in Excel
Comprehensive VBA Notes in Excel
VBA (Visual Basic for Applications) in Excel is a programming language developed by Microsoft. It
allows users to automate repetitive tasks, create custom forms, manipulate data, and extend Excel's
functionality. VBA is especially useful for users who need to process large amounts of data or
perform complex calculations.
Sub HelloWorld()
End Sub
Prompts the user to enter their name and then displays a greeting.
Sub GreetUser()
End Sub
Loops through cells in the range A1:A10 and sets each cell's value to 'Sample'.
Sub FillCells()
Dim i As Integer
For i = 1 To 10
End Sub
A function that takes two numbers as input and returns their sum.
AddNumbers = x + y
End Function
Sub ClearCells()
Range("B1:B10").ClearContents
End Sub
Checks if the value in cell A1 is greater than 50 and displays a message based on the result.
Sub CheckValue()
Else
End If
End Sub
Sub CopyData()
Range("B1").Value = Range("A1").Value
End Sub
Finds the first empty row in column A and inserts 'New Entry'.
Sub InsertInFirstEmptyRow()
End Sub
Sub DisplayDateTime()
Range("A1").Value = Now
End Sub
Uses a Do...While loop to set values in column A from row 1 until row 10 with the text 'Row #'
followed by the row number.
Sub DoWhileLoopExample()
Dim i As Integer
i = 1
Do While i <= 10
i = i + 1
Loop
End Sub