Results 1 to 12 of 12

Thread: Match worksheet function in VBA searching on multiple criteria

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #5
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,970
    Quote Originally Posted by Mellstock View Post
    I have found something that seems to work which is:
    Sub Findclose()
    Range("K4").Select
    Range("K4").Value = WorksheetFunction.Index(Range("F2:F34"), WorksheetFunction.Match(Range("K2"), Range("A2:A34"), 0) + WorksheetFunction.Match(Range("K3"), Range("B2:B34"), 0) - 1)
    End Sub
    This is nonsense.
    "Seems" is the operative word.
    Try running it in the file you linked to in msg#1 looking for 5:00 10 March 2020
    Also try looking for 5:00 9th March 2020 which isn't in the list - it returns a value!

    Addition after posting:
    Attached, that file with a button to run your line of code, and the other two I suggested earlier, and puts the 3 results into K4:M4.
    First search for 17:15 9th March 2020; all fine, three similar results in cells K4, L4 & M4.
    Second, search for 5:00 10 March 2020; Correct results in L4 and M4, your code throws an error.
    Now try 5:00 9th March 2020 for which there is no data in the table; L4 and M4 both display correcly #N/A, whereas your code return a value of 13055! (This is the close on the 10th March at 5am)
    Attached Files Attached Files
    Last edited by p45cal; 03-29-2020 at 05:44 AM.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

Posting Permissions

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