VBA lookup

delexcel

Board Regular
Joined
Feb 22, 2007
Messages
185
Hi,

I have the following code:

Code:
=IFERROR(MIN(
    IF(TEXT($A$2:$A$154810,"mmm")=$L40,
    IF($B$2:$B$154810>=N$38,
    IF($B$2:$B$154810<=N$39,
    IF(ISNUMBER($C$2:$C$154810),
    $C$2:$C$154810))))),"")

At present it is searching range $A$2:$A$154810, comparing the month of a cell in the range, to cell L40, which states a month.

If the month is the same, then it is searching range $B$2:$B$154810 to check whether the time of a cell in the range is between two different times (N38 & N39).

If all of those are true, then it returns a number in the range $C$2:$C$154810.

MY QUERY ...

At present, the first query is just looking up the month (mmm) of the date in the range $A$2:$A$154810.

Is it possible to ALSO look up the day (d) of the date in the range? And compare it to a 'day value' (1-31) in cell M40?

I tried modifing:

IF(TEXT($A$2:$A$154810,"mmm")=$L40,

to

IF(AND(TEXT($A$2:$A$154810,"mmm")=$L40,TEXT($A$2:$A$154810,"d")=$M40),

but unfortunately that did not work.
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
If the value in M40 is numerical you can't compare it with a text value of a number, it won't match. Try using the DAY() function instead of the TEXT() function?
 
Upvote 0
What about something like...

=IF(AND(TEXT($A$2:$A$154810,"mmm")=$L40,TEXT($A$2:$A$154810,"d")=TEXT($M40,"0"))
 
Upvote 0
Thank you to those who have posted replies.

Unfortunately it is still not working.

The following code that is looking up the day is working:

Code:
=IFERROR(MIN(
    IF(VALUE(TEXT($A$2:$A$154810,"d"))=$M40,
    IF($B$2:$B$154810>=N$38,
    IF($B$2:$B$154810<=N$39,
    IF(ISNUMBER($C$2:$C$154810),
    $C$2:$C$154810))))),"")

As is the original code that was looking up the month.

However trying to specify that the day AND the month must be the same before it proceeds does not seem to work.

Any suggestions would be greatly appreciated.
 
Upvote 0
Thank you to those who have posted replies.

Unfortunately it is still not working.

The code that is looking up the day is now working:

IF(VALUE(TEXT($A$2:$A$154810,"d"))=$M40,

As is the original code that was looking up the month.

However trying to specify that the day AND the month must be the same before it proceeds does not seem to work.

That being said, I have been successfully able to combine the day and the month in the following code, however the difference is I made the range much shorter - why would this cause the problem?

Code:
=IFERROR(MIN(
    IF(AND(VALUE(TEXT(A50:A58,"D"))=$M40,TEXT(A50:A58,"MMM")=TEXT($L40,"0")),
    IF(B50:B58>=G$38,
    IF(B50:B58<=G$39,
    IF(ISNUMBER(C50:C58),
   C50:C58))))),"")

Any suggestions would be greatly appreciated.
 
Upvote 0
I just discovered an interesting point.

Code:
=IFERROR(MIN(
    IF(AND(VALUE(TEXT(A50:A58,"D"))=$M40,TEXT(A50:A58,"MMM")=TEXT($L40,"0")),
    IF(B50:B58>=G$38,
    IF(B50:B58<=G$39,
    IF(ISNUMBER(C50:C58),
   C50:C58))))),"")

The above code works because the range A50:A58 only spans one day.

As soon as the range is increased to more than one day the result returned is zero again.
 
Upvote 0
What are you attempting to do

find a date/time? or many date/times between a date and a time slot?

what do you want to return if there is more than result one entry for your criteria

?? so to reiterate what are you attempting to do?
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,844
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top