Written by Allen Wyatt (last updated April 10, 2021)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and 2021
Excel allows you to easily edit formulas. In doing so, you can quickly change a cell reference or a range reference from relative to absolute. What if you have a large number of cells in which you need to change from relative to absolute referencing? In this instance, the nature of the problem is well-suited to being solved through a macro.
By using the ConvertFormula method available in VBA, you can easily convert a formula from relative to absolute addressing. The following short macro uses this method to change the addressing method used in a range of cells:
Sub Relative2Absolute() Dim c As Range For Each c In Selection If c.HasFormula = True Then c.Formula = Application.ConvertFormula(c.Formula, _ xlA1, xlA1, xlAbsolute) End If Next c End Sub
The key to how this macro works is, of course, in the ConvertFormula method. The last parameter used by the method is—in this case—xlAbsolute. If you want to adapt the macro so that it changes to other types of addressing, you can change xlAbsolute to xlRelative, xlAbsRowRelColumn, or xlRelRowAbsColumn. (I'm sure you can figure out the purpose of each constant by its name.)
There is one other thing to remember regarding the ConvertFormula method: It has a length limit of 255 characters. That means that if your formula is very long, it is possible that the method won't work as you'd like. The best way to figure out if it will work for your needs is to test it out.
Note:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (10738) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and 2021. You can find a version of this tip for the older menu interface of Excel here: Converting from Relative to Absolute.
Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!
If you have a lot of values in a single row, you might want to pull the last non-zero value from that row. There are a ...
Discover MoreDo you ever have a need to return just a few digits out of a number? This tip shows different formulas you can use to ...
Discover MoreDo you need to know how many precedents or dependents there are on a worksheet? You could count them manually, or you ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2021-10-07 15:54:14
SMW
One problem with this - the insertion of @ sign:
=INDEX(C86:CI109,ROW(A1),
LARGE(IF(LEN(C86:CI86)>0,
COLUMN(C86:CI186),""),
COLUMNS(A1:A1))-COLUMNS(A1:B1))
becomes:
=@INDEX($C$86:$CI$109,ROW($A$1),
LARGE(IF(LEN(@$C$86:$CI$86)>0,@
COLUMN($C$86:$CI$186),""),
COLUMNS($A$1:$A$1))-COLUMNS($A$1:$B$1))
and vice versa
Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2025 Sharon Parq Associates, Inc.
Comments