View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Searching multiple columns

assuming the column headers are these
"benefit_name"
"benefit_amount_name"
"benefit_amount_method"

This should get you started.

Sub findStuff()
Dim v As Variant, v1 As Variant
Dim i As Long, k As Long, sAddr As String
Dim res As Variant, bMatch As Boolean
Dim rng() As Range, rng1 As Range
Dim rng2 As Range
v = Array( _
"benefit_name", _
"benefit_amount_name", _
"benefit_amount_method")
v1 = Array( _
"specifcName", _
"specificAmountName", _
"specific_method")
ReDim rng(LBound(v) To UBound(v))
For i = LBound(v) To UBound(v)
res = Application.Match(v(i), Rows(1).Cells, 0)
Set rng(i) = Range("A1").Offset(0, res - 1)
rng(i).Interior.ColorIndex = 5
Next
Set rng1 = Columns(rng(LBound(rng)).Column).Cells
Debug.Print rng1.Address
Set rng2 = rng1.Find(v1(LBound(v1)), rng(LBound(rng))(1))
If Not rng2 Is Nothing Then
sAddr = rng2.Address
Do
bMatch = True
rng2.Interior.ColorIndex = 6
For k = LBound(v) + 1 To UBound(v)
If Cells(rng2.Row, rng(k).Column).Value < v1(k) Then
Cells(rng2.Row, rng(k).Column).Interior.ColorIndex = 7
bMatch = False
Exit For
Else
Cells(rng2.Row, rng(k).Column).Interior.ColorIndex = 6
End If
Next
If bMatch Then
Worksheets("ABC").Range("B9").Value _
= Cells(rng2.Row, 21).Value
Exit Sub
End If
Set rng2 = rng1.FindNext(rng2)
Loop While rng2.Address < sAddr
End If
End Sub


--
Regards,
Tom Ogilvy




"Robin" wrote in message
...
I hope I can explain this clearly enough. And I thank you in advance for

any
suggestions or thoughts on this.

I have 3 columns of data (locations are dynamic, but the column headers

will
always be as shown below)
I want to search the first column for a specific benefit, then search the
second column using those rows that had the value from the first search.

I
want to search the second column for a match, then search the third column
(based on results from the previous matches) and find a final value in a
fourth column.

Example:
"benefit_name" "benefit_amount_name"
"benefit_amount_method"

Long Term Care
SSAB
Long Term Disability
Capital Accumulation Account CAA Salary
Percent
SSAB
Vision
Capital Accumulation Account Salary Deferral Fixed Amount
SSAB
Long Term Disability
Capital Accumulation Account CAA Remaining
Allowance Pct.


I want to find the Capital Accumulation Account benefit where the
benefit_amount_name = CAA and the benefit_amount_method = Remaining

Allowance
Pct.

If I could do this in VBA, that would be slick. I want this to be unseen

by
the end user. I just want to grab the value I'm looking for and plop it

into
a cell.
Is there a way to do this?