+ Reply to Thread
Results 1 to 7 of 7

Thread: Return a Value From a Range

  1. #1
    Registered User
    Join Date
    12-24-2010
    Location
    AS
    MS-Off Ver
    Excel 2007
    Posts
    11

    Question Return a Value From a Range

    Hi,

    How do I return a value if it the criteria is within the range given.

    As attached, how can I get the cell B21 as "B" if it's fall within the range of 1 to 1.99.

    Appreciate your helps.

    Regards,
    Haan
    Attached Files Attached Files
    Last edited by haan; 06-08-2011 at 07:07 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    06-03-2011
    Location
    Poland
    MS-Off Ver
    Excel 2003 / XP
    Posts
    412

    Re: Return a Value From a Range

    Hello try this (copy it into sheet1 code)

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim r As Integer
    Dim val As Double
    
    r = 2 'start row
    If Target.Address = "$B$20" Then
        Do Until Cells(r, 1).Value = ""
          If Target.Value >= Cells(r, 1).Value And Target.Value <= Cells(r, 2).Value Then
            Range("B21").Value = Cells(r, 3).Value
            Exit Sub
          End If
        r = r + 1
        Loop
        Range("B21").Value = ""
    End If
    End Sub
    working example in attached file

    Best Regards
    Attached Files Attached Files

  3. #3
    Valued Forum Contributor mohd9876's Avatar
    Join Date
    05-04-2011
    Location
    Amman, Jordan
    MS-Off Ver
    Excel 2010
    Posts
    409

    Re: Return a Value From a Range

    enter this formula in cell B21:
    =IF(AND(B20<=1.9,B20>=1),"B","")

  4. #4
    Valued Forum Contributor
    Join Date
    06-03-2011
    Location
    Poland
    MS-Off Ver
    Excel 2003 / XP
    Posts
    412

    Re: Return a Value From a Range

    Quote Originally Posted by mohd9876 View Post
    enter this formula in cell B21:
    =IF(AND(B20<=1.9,B20>=1),"B","")

    mohd9876: there are more than one condition -> see into file ;-)

    Best Regards

  5. #5
    Valued Forum Contributor
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2003
    Posts
    2,488

    Re: Return a Value From a Range

    hi, haan, solution with formula without VBA
    Attached Files Attached Files

  6. #6
    Valued Forum Contributor
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2003
    Posts
    2,488

    Re: Return a Value From a Range

    a bit simpler
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    12-24-2010
    Location
    AS
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Return a Value From a Range

    Hi Guys,
    Thanks. I've figured it out...
    It can be as easy as vlookup(...., ,1)
    use "1" instead of "0", then it can be within the range.

    Thanks.

    Regards,
    Haan

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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