Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 132
Default match multiple criteria using VBA

Could someone please tell me why my computer hates me...
Here's my code, not sure why it won't work. I've tried my variations of it.
Any ideas??? (By the way, "NB" is a named reference within the workbook.)

Function gather2(cond As String, HI As Integer, mode As Integer) As Double
Dim nrow As Integer
Dim ncol As Integer
Dim ans As Double
Dim mysheet As Worksheet
Dim hrange As Range
Dim mrange As Range
Dim frange As Range
Dim FinalRow As Integer

Set mysheet = Worksheets("Results")

ncol = Application.WorksheetFunction.Match(cond, mysheet.Range("1:1"), 0)
FinalRow = mysheet.Cells(Row.Count, ncol).End(xlUp).Row
Set hrange = mysheet.[cells(3,ncol)].Resize(FinalRow - 2, 1)
Set mrange = mysheet.[cells(3,ncol-1)].Resize(FinalRow - 2, 1)
Set frange = mysheet.[cells(3,ncol+1)].Resize(FinalRow - 2, 1)

If HI = 0 Or HI = Application.WorksheetFunction.Floor((Range("NB") / 2), 1)
Then

nrow = mysheet.Evaluate("Match(1,(" & hrange.Address & "=" & HI & ")*("
& mrange.Address & "=" & mode & "),0)")

ElseIf HI 0 And HI < Application.WorksheetFunction.Floor((Range("NB") /
2), 1) Then

nrow = mysheet.Evaluate("Match(1,(" & hrange.Address & "=" & HI & ")*("
& mrange.Address & "=" & mode & "*2),0)")

End If

ans = Application.WorksheetFunction.Index(mysheet.[3:65536], nrow, ncol + 1)
gather2 = ans
End Function

Thanks for any help!
Anna
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default match multiple criteria using VBA

have n o idea what it does but this tidies a few bits. It would help if you
gave more detail when you post, we can't raed your mind

Function gather2(cond As String, HI As Integer, mode As Integer) As Double
Dim nrow As Integer
Dim ncol As Integer
Dim ans As Double
Dim mysheet As Worksheet
Dim hrange As Range
Dim mrange As Range
Dim frange As Range
Dim FinalRow As Long

Set mysheet = Worksheets("Results")

ncol = Application.WorksheetFunction.Match(cond, mysheet.Range("1:1"), 0)
FinalRow = mysheet.Cells(mysheet.Rows.Count, ncol).End(xlUp).Row
Set hrange = mysheet.Cells(3, ncol).Resize(FinalRow - 2, 1)
Set mrange = mysheet.Cells(3, ncol - 1).Resize(FinalRow - 2, 1)
Set frange = mysheet.Cells(3, ncol + 1).Resize(FinalRow - 2, 1)

If HI = 0 Or HI = Application.WorksheetFunction.Floor((Range("NB") / 2), 1)
Then

nrow = mysheet.Evaluate("Match(1,(" & hrange.Address & "=" & HI & _
")*(" & mrange.Address & "=" & mode & "),0)")

ElseIf HI 0 And HI < Application.WorksheetFunction.Floor((Range("NB") /
2), 1) Then

nrow = mysheet.Evaluate("Match(1,(" & hrange.Address & "=" & HI & _
")*(" & mrange.Address & "=" & mode & "*2),0)")

End If

ans = Application.WorksheetFunction.Index(mysheet.Rows(" 3:65536"), nrow,
ncol + 1)
gather2 = ans
End Function

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"anna" wrote in message
...
Could someone please tell me why my computer hates me...
Here's my code, not sure why it won't work. I've tried my variations of

it.
Any ideas??? (By the way, "NB" is a named reference within the workbook.)

Function gather2(cond As String, HI As Integer, mode As Integer) As Double
Dim nrow As Integer
Dim ncol As Integer
Dim ans As Double
Dim mysheet As Worksheet
Dim hrange As Range
Dim mrange As Range
Dim frange As Range
Dim FinalRow As Integer

Set mysheet = Worksheets("Results")

ncol = Application.WorksheetFunction.Match(cond, mysheet.Range("1:1"), 0)
FinalRow = mysheet.Cells(Row.Count, ncol).End(xlUp).Row
Set hrange = mysheet.[cells(3,ncol)].Resize(FinalRow - 2, 1)
Set mrange = mysheet.[cells(3,ncol-1)].Resize(FinalRow - 2, 1)
Set frange = mysheet.[cells(3,ncol+1)].Resize(FinalRow - 2, 1)

If HI = 0 Or HI = Application.WorksheetFunction.Floor((Range("NB") / 2),

1)
Then

nrow = mysheet.Evaluate("Match(1,(" & hrange.Address & "=" & HI &

")*("
& mrange.Address & "=" & mode & "),0)")

ElseIf HI 0 And HI < Application.WorksheetFunction.Floor((Range("NB") /
2), 1) Then

nrow = mysheet.Evaluate("Match(1,(" & hrange.Address & "=" & HI &

")*("
& mrange.Address & "=" & mode & "*2),0)")

End If

ans = Application.WorksheetFunction.Index(mysheet.[3:65536], nrow, ncol +

1)
gather2 = ans
End Function

Thanks for any help!
Anna



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Match / Index multiple criteria return multiple results Marty Excel Worksheet Functions 2 May 22nd 10 01:49 PM
MATCH Multiple Criteria & Return Previous / Penultimate Match Sam via OfficeKB.com Excel Worksheet Functions 27 October 6th 07 01:39 AM
match multiple criteria ina range from multiple criteria multiplet RG Excel Worksheet Functions 8 September 28th 07 04:21 AM
Index & Match functions - multiple criteria and multiple results [email protected] Excel Worksheet Functions 4 May 2nd 07 03:13 AM
MATCH using multiple criteria? Bob Tarburton Excel Programming 6 February 2nd 06 02:11 PM


All times are GMT +1. The time now is 12:17 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"