=INDEX([From.xlsx]Sheet1!$B$22:$AA$22,MATCH(B1,[From.xlsx]Sheet1!$B$1:$AA$1,1)) Seems to work just fine, but that's not a VBA macro.
I can translate that into a UDF like this:
As programmed, both approaches return an N/A error when the date is in "To" is before the first date in "From". Of course, you can use IFERROR() or IFNA() to do something with that error, if desired.
Standard rule of thumb is that the native worksheet formula approach will execute faster than VBA, and I would expect that to be the case here as well. Another advantage to the native worksheet formula approach is that the formula will work just fine when the "From" workbook is closed, where the VBA approach will require that "From" be open. You as the programmer will need to decide which of the two programming languages you prefer (I think there are good reasons to prefer native worksheet formulas over VBA in this case, but I don't know all of what you are trying to do with this project).
Bookmarks