|  

» Simplifying Formulas by Defining Names for Often-Repeated Parts

Problem:

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))


Rate This Tip
12 34 5
Rating: 2.67     Views: 5822
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?
Click here to post comment
For Registered Users
Name
Comment Title
Comments