Excel

Change formula reference type

Ease of Use

Easy

Version tested with

2000, 2002 

Submitted by:

Justinlabenne

Description:

Changes a selected range of formulas to Absolute cell references 

Discussion:

At times you may want to convert a group of formulas to another cell reference type when copying / pasting / dragging down / etc... This code will convert a selected range of formulas to absolute reference type Ex: ($A$1) it can be modified for use other reference styles as well" xlAbsRowRelColumn, xlRelRowAbsColumn, xlRelative 

Code:

instructions for use

			

Option Explicit Sub AdjustFormulaRefType() ' Change formula reference types to Absolute: ' xlAbsolute, xlAbsRowRelColumn, xlRelRowAbsColumn, or xlRelative Dim rRng As Range On Error Resume Next For Each rRng In Application.Intersect(Selection, Selection.SpecialCells(xlCellTypeFormulas)) Err.Clear If Range(rRng.Address).HasFormula = False Then MsgBox "There are no formulas within the selection", 64 Exit Sub Else Application.ScreenUpdating = False Application.Calculation = xlCalculationManual Application.EnableEvents = False If Err.Number <> 0 Then GoTo ErrExit: Range(rRng.Address).Formula = Application.ConvertFormula _ (Range(rRng.Address).Formula, 1, 1, xlAbsolute) End If Next rRng ErrExit: Application.EnableEvents = True Application.Calculation = xlCalculationAutomatic Application.ScreenUpdating = True End Sub

How to use:

  1. Open an Excel Workbook
  2. Copy the code
  3. Press Alt + F11 to open the Visual Basic Editor (VBE)
  4. Select INSERT > MODULE from the menubar
  5. Paste code into the right pane
  6. Press Alt+Q to return to Excel
  7. Save workbook before any other changes
 

Test the code:

  1. Select a range of cells containing formulas
  2. Go to TOOLS > MACRO > MACROS
  3. When the dialog appears, select {AdjustFormulaRefType}
  4. Press Run
 

Sample File:

Change Ref-Type.zip 8.01KB 

Approved by mdmackillop


This entry has been viewed 119 times.

Please read our Legal Information and Privacy Policy
Copyright @2004 - 2020 VBA Express