What is VBA?
Example:
Sub HelloWorld()
MsgBox "Hello, World!"
End Sub
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
WithoutBook brings subject-wise interview questions, online practice tests, tutorials, and comparison guides into one responsive learning workspace.
Know the top VBA interview questions and answers for freshers and experienced candidates to prepare for job interviews.
Know the top VBA interview questions and answers for freshers and experienced candidates to prepare for job interviews.
Search a question to view the answer.
Example:
Sub HelloWorld()
MsgBox "Hello, World!"
End Sub
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Example:
Dim myVar As String
myVar = "Hello"
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Example:
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets(1)
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Example:
Dim cell As Range
For Each cell In Range("A1:A10")
Debug.Print cell.Value
Next cell
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Example:
'Option Explicit
Sub Example()
Dim x As Integer
y = 10 ' This will cause an error without 'Option Explicit'
End Sub
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Example:
Sub Example()
If condition Then
Exit Sub
End If
' Rest of the code
End Sub
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Example:
Sheets.Add After:=Sheets(Sheets.Count)
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Example:
If x > 10 Then
Debug.Print "x is greater than 10"
ElseIf x < 10 Then
Debug.Print "x is less than 10"
Else
Debug.Print "x is equal to 10"
End If
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Example:
Do While i < 10
Debug.Print i
i = i + 1
Loop
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Example:
Const PI As Double = 3.14159
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Example:
On Error Resume Next
' code that may cause an error
On Error GoTo 0
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Example:
For i = 1 To 10
Debug.Print i
Next i
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Example:
MsgBox "Hello, World!", vbInformation + vbOKOnly, "Greeting"
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Example:
Call MyProcedure()
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Example:
Dim myArray(1 To 3) As Integer
myArray(1) = 10
myArray(2) = 20
myArray(3) = 30
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Example:
Dim userInput As String
userInput = InputBox("Enter your name:", "User Input")
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Example:
Application.ScreenUpdating = False
' Your code here
Application.ScreenUpdating = True
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Example:
Sub ModifyValue(ByRef x As Integer)
x = x + 1
End Sub
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Example:
On Error Resume Next
' code that may cause an error
On Error GoTo 0
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Example:
With Range("A1")
.Value = 42
.Font.Bold = True
End With
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Example:
ActiveCell.Value = "Hello"
Selection.Font.Bold = True
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Example:
Sub ShowUserForm()
UserForm1.Show
End Sub
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Example:
Application.ScreenUpdating = False
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Example:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A1:A10")) Is Nothing Then
' Code to execute when cells in A1:A10 are changed
End If
End Sub
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Example:
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets("Sheet1")
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Example:
Select Case x
Case 1
Debug.Print "Value is 1"
Case 2
Debug.Print "Value is 2"
Case Else
Debug.Print "Value is neither 1 nor 2"
End Select
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Example:
ActiveCell.Offset(1, 2).Value = "Data"
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Example:
Unload UserForm1
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Example:
Dim myArray(1 To 10) As Integer
Debug.Print LBound(myArray) ' Outputs 1
Debug.Print UBound(myArray) ' Outputs 10
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Example:
Function AddNumbers(x As Integer, y As Integer) As Integer
AddNumbers = x + y
End Function
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.