Hello everyone, I just want to give a welcome shout out for everyone who will help me (or attempt to)

Here's my problem. I have four columns in excel that represent my raw data table. For the sake of this post lets call them "col1" with text values, "col2" with text values, "col3" with numerical values, and "col4" with numerical values. I want a function that will return the text value from "col2" that equals a known text from "col1" and the minimum the value from "col4" and the minimum value from "col3". I also want to choose between returning the value from "col2" with the smallest value from "col3" or the second smallest value from "col3".

I'm not good with excel or vba enough to know what is the best way of doing this. Someone recommended I use DMIN(), but that requires I maintain a separate criteria table with a certain formatting and I just can't do that since I need to perform this operation like a 100 times. I don't want 100 criteria tables. DMIN() isn't any good for return text values either.

When I was thinking about this, this is me spit-balling here, I felt the best thing do to would be to have a function like:

Function TBUY(col1value as string, range col2, optional min as double)
If min is present, I know I have to find the "col2" value corresponding to second smallest value from the "col3" where "col1" = col1value and "col4" is minimized. If min is not present, then I know to simply find the smallest value.

I'm a complete beginner with excel vba, please advise the function design and syntax.