Basic VBA Programs in Excel
Basic VBA Programs in Excel
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
Next i
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