+ Reply to Thread
Results 1 to 2 of 2

Thread: Simplifying Formulas by Defining Names for Often-Repeated Parts

  1. #1
    K.S.
    Guest

    Re: Simplifying Formulas

    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?

  2. #2
    Valued Forum Contributor
    Join Date
    12-07-2004
    Posts
    598

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

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0