Excel User Group
Microsoft Excel blogs, forums, files. Read, ask questions, provide answers.

if / then formulas (conditional?)

Latest post Thu, Apr 24 2008 3:24 PM by floodzone. 6 replies.
  • Thu, Apr 24 2008 12:31 AM

    • floodzone
    • Top 150 Contributor
    • Joined on Thu, Apr 24 2008
    • Posts 3
    • Points 47

    if / then formulas (conditional?)

    I would like to write a formula that would recognize a numeric value in a given cell and display another numeric value that is linked to (or associated with) it in the formula cell.  for example:  let's say #1 = 75, 2 = 136, 3=98, and so on, up to #250 = whatever.  Is there a formula that would recognize the number 1, or 2, or 3, etc. in a column of cells and display its associated value in another column of cells?

    Another example:  If I type "1" in cell a-1 then cell b-1 displays the number "75".  If I change a-1 to "2" then b-1 displays "136".  I need to be able to assign totally arbitrary values to the numbers 1 thru 250 and have those values show up in my formula cells.  Once I do this for a-1 and b-1 I should be able to repeat it on down the rows or in columns to the right of a and b.

    Hope this makes sense.  i would appreciate any advice.

    • Post Points: 37
  • Thu, Apr 24 2008 1:41 AM In reply to

    • Nick Hodge
    • Top 10 Contributor
    • Joined on Sun, Dec 23 2007
    • Southampton
    • Posts 304
    • Points 5,058
    • MVP

    Re: if / then formulas (conditional?)

    Floodzone

    As you have so many conditions I would use a separate table and a Vlookup formula, so image you have a table on Sheet2 covering A1:B250, with the values 1-250 in A1:A250 and the associated 'arbitrary values' in B1:B250, then on sheet1 in B1 type

    =VLOOKUP(A1,Sheet2!$A$1:$B$250,2,FALSE)

    This will leave you with N/A# in B1 until you enter a 'matching' value from the list in Sheet2, to overcome that, just add an error checking routine.

    =IF(ISERROR(VLOOKUP(A1,Sheet2!$A$1:$B$250,2,FALSE)),"",VLOOKUP(A1,Sheet2!$A$1:$B$250,2,FALSE))

    Regards
    Nick Hodge
    Microsoft MVP, Excel
    Southampton, UK

    Filed under:
    • Post Points: 21
  • Thu, Apr 24 2008 8:26 AM In reply to

    • br7250
    • Top 25 Contributor
    • Joined on Fri, Apr 4 2008
    • Virginia, USA
    • Posts 34
    • Points 458

    Re: if / then formulas (conditional?)

     Regarding your random number generation, in cell reference B1 to B250 (or whatever number is your last number), enter the following formula: =ROUND(RAND()*250,0)

    If you press the F9 key, it should change automatically, whatever values you enter in column A.

    Regards,

    Bruce Reynolds

    Excel Power User and Model Developer

    • Post Points: 5
  • Thu, Apr 24 2008 9:43 AM In reply to

    • fossildon
    • Top 150 Contributor
    • Joined on Mon, Mar 31 2008
    • Posts 2
    • Points 58

    Re: if / then formulas (conditional?)

     Instead of using the redundant IsError() paste

    Public Function ifError(ByRef ToEvaluate As Variant, Optional Default As Variant = 0) As Variant

        If isError(ToEvaluate) Then
            ifError = Default
        Else
            ifError = ToEvaluate
        End If
       
    End Function

    into your VBE then use a much abbreviated formula that Nick gave like

    =IfError(VLOOKUP(A1,Sheet2$A$1:$B$250,2,FALSE),"")

    • Post Points: 21
  • Thu, Apr 24 2008 11:10 AM In reply to

    • Nick Hodge
    • Top 10 Contributor
    • Joined on Sun, Dec 23 2007
    • Southampton
    • Posts 304
    • Points 5,058
    • MVP

    Re: if / then formulas (conditional?)

    Or for completeness if you have Excel 2007 use the built-in IFERROR function

    =IFERROR(VLOOKUP(A1,Sheet2$A$1:$B$250,2,FALSE),"")

    Regards
    Nick Hodge
    Microsoft MVP, Excel
    Southampton, UK

    Filed under: ,
    • Post Points: 21
  • Thu, Apr 24 2008 3:16 PM In reply to

    • floodzone
    • Top 150 Contributor
    • Joined on Thu, Apr 24 2008
    • Posts 3
    • Points 47

    Re: if / then formulas (conditional?)

    thanks all,

     

    let me take some time to see if I can make any of those ideas work.  I appreciate the help.

    • Post Points: 5
  • Thu, Apr 24 2008 3:24 PM In reply to

    • floodzone
    • Top 150 Contributor
    • Joined on Thu, Apr 24 2008
    • Posts 3
    • Points 47

    Re: if / then formulas (conditional?)

    Okay got it to work with vlookup.  Thank you all very much

    • Post Points: 5
Page 1 of 1 (7 items) | RSS
Copyright Excel User Group and the relevant contributors, 2008. All Trade Marks acknowledged. This site is a peer-to-peer site and NOT affiliated in any way to Microsoft Corp. All rights reserved.