» Simplifying Formulas by Defining Names for Often-Repeated Parts
CATEGORY - Excel Formula and Function
VERSION - All Microsoft Excel Versions
The following formula searches column A for each of the serial numbers listed in column C.
It then analyses the corresponding number from column B: for numbers less than or equal to 40, 10 is added; and for numbers greater than or equal to 90, 10 is subtracted. Other numbers are returned as is.
=IF(VLOOKUP($C2,$A$2:$B$5,2,FALSE)>=90,VLOOKUP($C2,$A$2:$B$5,2,FALSE)-10,IF(VLOOKUP($C2,$A$2:$B$5,2,FALSE)<=40,VLOOKUP($C2,$A$2:$B$5,2,FALSE)+10,VLOOKUP($C2,$A$2:$B$5,2,FALSE)))
As can be seen, the underlined VLOOKUP part of the formula is repeated a number of times, thus creating a long and very complicated formula.
To make our spreadsheet easier to understand, we would like to simplify the formula.
Solution:
Step1: Define a name for the repeated part of the formula:
Select a cell > Insert > Name > Define > type the name "value" in the Names in workbooks text box > and enter the following formula in the Refers to box:
=VLOOKUP($C2,$A$2:$B$5,2,FALSE)
Step 2: Enter the following formula in cell D2, and copy it down the column:
=IF(value>=90,value-10,IF(value<=40,value+10,value))
Book Store:
Recommended Books:
- How to Use Financial Statements: A Guide to Understanding the Numbers
- The Interpretation of Financial Statements
- Retire Young, Retire Rich
- The Financial Numbers Game: Detecting Creative Accounting Practices
- Successful Business Planning in 30 Days: A Step-By-Step Guide for Writing a Business Plan and Starting Your Own Business
- Microsoft Windows XP Inside Out
Re: Simplifying Formulas
K.S.
Is there a way to do this in VBA? For example, if my VBA code contains many repetitions of something like "Sheets("WeeklyReport").Range("B1").Value," is there a way to replace that with something shorter?

