YUNOVA · Excel for work · Module 26: Automation/VBA
Record/secure/inspect/clean VBA macros
Record/secure/inspect/clean VBA macros
Key points
- Developer tab: File > Options > Customize Ribbon > Developer tick। फिर Developer > Record Macro से steps record करें।
- Record से पहले "Use Relative References" तय करें: off हो तो macro हमेशा उन्हीं cells (जैसे A1) पर चलेगा।
- Alt+F11 से VBA Editor में code देखें। Recorder के .Select/Selection हटाकर सीधा लिखें: Range("A1").Font.Bold = True।
- Macro के बाद Ctrl+Z काम नहीं करता—पहले save करें। Email/internet की file के macros सिर्फ भरोसेमंद source से चलाएँ।
- Macro का ढाँचा: Sub RunReport() … End Sub। Cell में value: Range("B2").Value = 100; row-column से: Cells(2, 3) = C2।
- शर्त: If Range("C2").Value > 1000 Then … Else … End If। Multi-line If में End If भूलने पर compile error आता है।
- आखिरी भरी row: lastRow = Cells(Rows.Count, "A").End(xlUp).Row; फिर For i = 2 To lastRow … Next i से हर row पर काम।
- Button: Developer > Insert > Form Controls > Button बनाकर macro assign करें; या shape पर right-click > Assign Macro।