Contoh Kode Macro Konversi Acuan Sel dalam Rumus Excel
Kali ini kami akan berbagi dua buah macro yang bertugas untuk mengkonversi acuan sel dalam suatu rumus Excel.
Kode Macro Konversi Acuan Sel Relatif Menjadi Absolut dalam Rumus
Saat rumus yang Anda gunakan dalam suatu worksheet rencananya akan diubah semua sel dan barisan sel acuannya dari yang semula acuan relatif agar menjadi absolut, maka Anda bisa menggunakan contoh kode macro berikut:
Sub KonversiRelatifKeAbsolut()
Dim x As Range, y As String, z As String
For Each x In Cells.SpecialCells(xlCellTypeFormulas)
y = x.Formula
z = _
Application.ConvertFormula _
(Formula:=y, fromReferenceStyle:=xlA1, _
toReferenceStyle:=xlA1, toAbsolute:=xlAbsolute)
x.Formula = z
Next x
End Sub
Dim x As Range, y As String, z As String
For Each x In Cells.SpecialCells(xlCellTypeFormulas)
y = x.Formula
z = _
Application.ConvertFormula _
(Formula:=y, fromReferenceStyle:=xlA1, _
toReferenceStyle:=xlA1, toAbsolute:=xlAbsolute)
x.Formula = z
Next x
End Sub
Kode Macro Konversi Acuan Sel Absolut Menjadi Relatif dalam Rumus
Dan inilah cara mengkonversi acuan sel absolut menjadi relatif:
Sub KonversiAbsolutKeRelatif()
Dim x As Range, y As String, z As String
For Each x In Cells.SpecialCells(xlCellTypeFormulas)
y = x.Formula
z = _
Application.ConvertFormula _
(Formula:=y, fromReferenceStyle:=xlA1, _
toReferenceStyle:=xlA1, toAbsolute:=xlAbsolute)
x.Formula = WorksheetFunction.Substitute(z, "$", "")
Next x
End Sub
Dim x As Range, y As String, z As String
For Each x In Cells.SpecialCells(xlCellTypeFormulas)
y = x.Formula
z = _
Application.ConvertFormula _
(Formula:=y, fromReferenceStyle:=xlA1, _
toReferenceStyle:=xlA1, toAbsolute:=xlAbsolute)
x.Formula = WorksheetFunction.Substitute(z, "$", "")
Next x
End Sub
Itulah sedikit contoh kode macro yang berfungsi mengkonversi acuan sel dari relatif menjadi absolut dan juga sebaliknya dalam suatu rumus di Excel.
Selamat mencoba dan semoga bermanfaat.
