Published on 2025-12-08T00:02:27+08:00
VBA Basics: Your First Excel Program
VBA Basics: Your First Excel Program
What is VBA?
Visual Basic for Applications (VBA) is Excel's built-in programming language for advanced automation.
Opening the VBA Editor
- Press Alt+F11
- Or go to Developer > Visual Basic
Your First Macro
Sub HelloWorld()
MsgBox "Hello World!"
End Sub
Variables
Dim name As String
Dim age As Integer
Dim price As Double
Dim isActive As Boolean
name = "John"
age = 25
Working with Cells
' Using Range
Range("A1").Value = "Hello"
' Using Cells (row, column)
Cells(1, 1).Value = "Hello"
' Reading values
Dim x As Variant
x = Range("A1").Value
Loops
' For loop
For i = 1 To 10
Cells(i, 1).Value = i
Next i
' For Each loop
For Each cell In Range("A1:A10")
cell.Value = cell.Value * 2
Next cell
Conditions
If Range("A1").Value > 100 Then
MsgBox "High"
ElseIf Range("A1").Value > 50 Then
MsgBox "Medium"
Else
MsgBox "Low"
End If
Conclusion
These VBA basics form the foundation for powerful Excel automation solutions.
Share this article
Related Posts
Automate Excel without VBA using Power Automate. Create flows that trigger on events, process data, and integrate with other apps.
2025-12-08T00:02:27+08:00
Build automated reporting systems in Excel. Learn to pull data, format reports, and generate outputs automatically with VBA.
2025-12-08T00:02:27+08:00
Start programming in Excel with VBA. Learn variables, loops, conditions, and write your first working macro from scratch.
2025-12-08T00:02:27+08:00