Page 3 of 3 FirstFirst 123
Results 21 to 22 of 22

Thread: Looking for Value in Another Column, Evaluating and Then Looking in Another Column

  1. #21
    Junior Member
    Join Date
    Feb 2013
    Posts
    26
    Rep Power
    0
    Quote Originally Posted by Rick Rothstein View Post
    Sorry about my absence...
    Yes, please! Welcome back! Thanks!

  2. #22
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    662
    Rep Power
    14
    Quote Originally Posted by olives View Post
    Yes, please! Welcome back! Thanks!
    Give this UDF a try...
    Code:
    Function Largest(CompareValue As Double, FirstNumberCell As Range, _
                     Optional SecondNumberCell As Range, _
                     Optional ReferenceColumn As Long = 1) As Variant
      Dim X As Long, Index As Long, TestValue As Variant, RefCell As Range
      Dim Source1 As Variant, Source2 As Variant, Results As Variant
      Application.Volatile
      If SecondNumberCell Is Nothing Then Set SecondNumberCell = FirstNumberCell.Offset(, 1)
      Source1 = FirstNumberCell.Resize(Cells(Rows.Count, FirstNumberCell.Column). _
                                       End(xlUp).Row - FirstNumberCell.Row + 1, 2)
      Source2 = SecondNumberCell.Resize(Cells(Rows.Count, SecondNumberCell.Column). _
                                        End(xlUp).Row - SecondNumberCell.Row + 1, 2)
      ReDim Results(1 To UBound(Source1), 1 To 1)
      For X = 1 To UBound(Source1)
        If Source1(X, 1) < CompareValue Then
          Index = Index + 1
          Results(Index, 1) = Source2(X, 1)
        End If
      Next
      If ReferenceColumn = 1 Then
        Set RefCell = FirstNumberCell
      Else
        Set RefCell = SecondNumberCell
      End If
      Largest = WorksheetFunction.Large(Results, Application.Caller.Row - RefCell.Row + 1)
    End Function
    Note the argument list has changed. The first argument is the number or reference to a cell containing the number you want to be lower than, the second argument is a reference to the cell containing the first number in the search column, the third argument is a reference to the cell containing the first number in the result column (the source and results lists do not have to both start on the same row), and the last argument is either a 1 or 2 depending on which column's first number the formula is aligned to (1 means the formula is on the same row as the source column's first number and 2 means the formula is on the same row as the result column's first number). The third argument is optional and if omitted, the result column defaults to the cells immediately to the right of the source cells (that makes it function exactly like my first posted UDF). The fourth argument is also optional and defaults to 1 (the source cells). So, assuming this...

    A1 - 100
    F3:F18 - contains source values to check against A1's value
    J3:J18 - contains result values where the largest value will be returned from
    M3 -=Largest(A1,F3,J3)

    However, for this arrangement...

    A1 - 100
    F3:F18 - contains source values to check against A1's value
    J23:J38 - contains result values where the largest value will be returned from
    M23 -=Largest(A1,F3,J23,2)
    Last edited by Rick Rothstein; 03-20-2013 at 06:15 AM.

Similar Threads

  1. Replies: 10
    Last Post: 05-23-2013, 12:30 PM
  2. Converting a Column Number to a Column Letter
    By Rasm in forum Excel and VBA Tips and Tricks
    Replies: 6
    Last Post: 12-17-2012, 02:29 AM
  3. Column to Row and Row to Column
    By lokvan in forum Excel Help
    Replies: 1
    Last Post: 11-30-2012, 09:30 AM
  4. Replies: 1
    Last Post: 08-07-2012, 11:04 PM
  5. Replies: 3
    Last Post: 08-05-2012, 09:16 PM

Posting Permissions

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