Excel · मराठी आवृत्ती
16.11 VBAचा सराव
या page मध्ये
- Exercise 1: Header bold/green macro record; दुसऱ्या sheetवर run.
- Exercise 2: Last used key row MsgBoxमध्ये.
- Exercise 3: City column trim.
- Exercise 4: Cancelled rows काढा.
- Exercise 5: Sheet names नवीन sheetवर list करा.
- Exercise 6: GSTAmount(amount,rate) UDF, दोन decimal places.
- Exercise 7: Missing Orders sheetसाठी error handler.
- रवींद्र बागले यांची tip
आधी स्वतः करून पाहा. अडल्यावर hint उघडा. Formulaचा result sampleच्या दोन-तीन rowsवर हाताने तपासा.
Exercise 1: Header bold/green macro record; दुसऱ्या sheetवर run.
Hint आणि तपासणी
Developer Record Macro, .xlsm save. Absolute cells असूनही unqualified sheet active असू शकते—target स्पष्ट करा.
Exercise 2: Last used key row MsgBoxमध्ये.
Hint आणि तपासणी
lastRow = ws.Cells(ws.Rows.Count,"A").End(xlUp).Rowws Set करा; no-data guard.
Exercise 3: City column trim.
Hint आणि तपासणी
For loopमधून validated text values; formula/error skip. VBA Trim टोकांचे spacesच काढतो; internal repeated spacesसाठी WorksheetFunction.Trim.
Exercise 4: Cancelled rows काढा.
Hint आणि तपासणी
फक्त disposable copyवर bottom-up For r=lastRow To2 Step−1. आधी count, नंतर reconciliation.
Exercise 5: Sheet names नवीन sheetवर list करा.
Hint आणि तपासणी
For Each ws In ThisWorkbook.Worksheets. Output sheet add झाल्यामुळे ती स्वतः listमध्ये येणार का ठरवा; existing sheet overwrite नको.
Exercise 6: GSTAmount(amount,rate) UDF, दोन decimal places.
Hint आणि तपासणी
Return amount*rate rounded2. VBA Round banker’s rounding वापरतो; worksheet ROUNDशी behavior वेगळा असू शकतो. Requirementनुसार WorksheetFunction.Round वापरा. Rate18%=0.18.
Exercise 7: Missing Orders sheetसाठी error handler.
Hint आणि तपासणी
On Error GoTo ErrHandler; meaningful message आणि shared cleanup path. Whole macroवर Resume Next नको.