# 12.2 Macro record करा — absolute की relative?

Source: https://ravindrabagale.com/mr/excel/ch12-macros-and-vba/12-2-recording-a-macro-absolute-vs-relative.html
Language: mr (Marathi with English technical terms)

Macro Recorder Excelमधल्या supported actionsचा VBA code बनवतो. Formatting शिकण्यासाठी चांगली सुरुवात; प्रत्येक UI action record होईलच असं नाही.

FormatHeader record करा

Developer › Record Macro. Name FormatHeader; spaces नको.

Store macro in This Workbook. Optional shortcut Ctrl + Shift + H; तो आधीच्या shortcutशी conflict करतो का तपासा.

A1:I1 select करा; Bold, dark green fill, white font.

Stop Recording. Alt + F11 › Modules › Module1मध्ये code पाहा.

Absolute recording

Sub FormatHeader()
'
' FormatHeader Macro
' Keyboard Shortcut: Ctrl+Shift+H
'
    Range("A1:I1").Select
    Selection.Font.Bold = True
    With Selection.Interior
        .Pattern = xlSolid
        .Color = 4616993
    End With
    Selection.Font.Color = RGB(255, 255, 255)
End Sub

Range A1:I1 fixed आहे. पण worksheet qualifier नसल्यामुळे हा recorder code active sheetवर चालू शकतो; “absolute” म्हणजे योग्य sheet आपोआप निवडतो असा अर्थ नाही.

Relative recording

Record करण्याआधी Developer › Use Relative References चालू करा. Current cellपासून एक row, नऊ columns असा example:

Sub FormatRowFromActiveCell()
    ActiveCell.Resize(1, 9).Select
    Selection.Font.Bold = True
    ActiveCell.Offset(1, 0).Select
End Sub

ActiveCell.Resize(1,9) current cell आणि उजवीकडचे आठ cells घेतो. Offset(1,0) एक row खाली जातो. Starting cell बदलल्यावर target बदलतो.

Practice

Absolute FormatHeader आणि relative HighlightRow—yellow fill—record करा. A1 आणि C5वरून चालवून फरक पाहा. Test copyवरच चालवा.

रवींद्र बागले यांची tip

आधी steps ठरवा आणि एकदा हाताने करून पाहा. चुकीच्या clicksचे recorded actionsही codeमध्ये येऊ शकतात. Absolute/relative mode मध्येच बदलल्यास mixed references नीट वाचा.
