How to Learn VBA
How to Learn VBA
Since you already work with SQL, Python, Power BI, and automation, VBA will be a
powerful tool for Excel automation, Power Query enhancements, and ETL workflows.
Dim x As Integer
x = 10
MsgBox x
Sub ShowMessage()
End Sub
End Function
Sub WriteToCell()
End Sub
Sub ChangeCell()
Dim ws As Worksheet
Set ws = ActiveSheet
End Sub
Sub LoopThroughCells()
cell.Value = "Updated"
Next cell
End Sub
Sub CopyData()
Sheets("Sheet1").Range("A1:D10").Copy
Sheets("Sheet2").Range("A1").PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
End Sub
Sub RefreshPowerQuery()
ActiveWorkbook.Queries("YourQueryName").Refresh
End Sub
Sub SaveAsPDF()
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:="C:\Reports\MyReport.pdf", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True
End Sub
Sub SendEmail()
With OutMail
.To = "[email protected]"
.Send
End With
End Sub
Sub ArrayExample()
Dim i As Integer
For i = 1 To 5
arr(i) = i * 10
Next i
End Sub
Sub RunSQLQuery()
Dim rs As Object
Debug.Print rs.Fields("CustomerName").Value
rs.MoveNext
Loop
rs.Close
conn.Close
End Sub
Using Debug.Print
Sub ErrorHandling()
On Error GoTo 0
End Sub
Mini-Exercise: Modify the above code to log errors in a text file.
Since you work with ETL, SQL, and Power BI, use VBA for:
Resources:
Excel VBA Documentation
Excel Macro Examples
VBA Forums (Experts Exchange, MrExcel)
Final Thoughts:
Since you already know SQL, Power BI, and automation, VBA will enhance your workflow.
Start with basic macros, then move to Excel automation, and finally advanced SQL &
Power Query integrations.
Would you like help with a specific VBA task or project idea?