# Vlookuping in different column according to time

#### ylijohe

##### Board Regular
I am making a program to compare stock prices. Unfortunately the free stock price server changes to position of the last prices when the market closes. When the market is open, I should vlookup column 2, but after closing time (8 pm or 20:00), Ishould vlookup column 4.

Any ideas how to solve this?
How to implement time checking to this formula:
VLOOKUP(A9;(VALUES!A\$1:D\$278);2;FALSE))

### Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
=if(now()<12:00,vlookup(1),vlookup(2))
You have to change the time to excel friendly time, but I believe the general format of the formula should work.

you could also use something along the lines of:
=VLOOKUP(A9,Values!A\$1:D\$278,2+((MOD(NOW(),1)>(20/24))*2),0)

good luck

=VLOOKUP(A9,VALUES!A\$1:D\$278,IF(MOD(NOW(),1<"20:00"+0,2,4),0)
This message was edited by Mark W. on 2002-09-17 14:17

On 2002-09-17 13:59, ylijohe wrote:
I am making a program to compare stock prices. Unfortunately the free stock price server changes to position of the last prices when the market closes. When the market is open, I should vlookup column 2, but after closing time (8 pm or 20:00), Ishould vlookup column 4.

Any ideas how to solve this?
How to implement time checking to this formula:
VLOOKUP(A9;(VALUES!A\$1:D\$278);2;FALSE))

=VLOOKUP(A9;VALUES!A\$1:D\$278,IF(C1>0.833333333333333,4,2),0)

where C1 houses the formula: =NOW()

You probably need to expand the condition of IF. The number 0.833333333333333 is the internal value of 20:00.

On 2002-09-17 13:59, ylijohe wrote:
...but after closing time (8 pm or 20:00), I should vlookup column 4.

Don't you mean at or after closing?

Yes. At OR after closing time...

How can I compare 0.833333333333333 and NOW(), or how to separate HOUR from NOW()?

Why not use...

=VLOOKUP(A9,VALUES!A\$1:D\$278,IF(MOD(NOW(),1)<"20:00"+0,2,4),0)
This message was edited by Mark W. on 2002-09-17 15:56

On 2002-09-17 14:40, ylijohe wrote:
Yes. At OR after closing time...

How can I compare 0.833333333333333 and NOW(), or how to separate HOUR from NOW()?

Using my formulation, you could use:

=VLOOKUP(A9,values!A\$1:D\$278,2+(HOUR(NOW())>=20)*2,0)

This works the same as the first, but incorporates your hour idea, which, to me, seems a bit cleaner than the backing into the time with the mod route.

Several other good options are presented here.

On 2002-09-17 14:45, Mark W. wrote:
Why not use...

=VLOOKUP(A9,VALUES!A\$1:D\$278,IF(MOD(NOW(),1<"20:00"+0,2,4),0)
This message was edited by Mark W. on 2002-09-17 14:47

ever so small typo:
=VLOOKUP(A9,values!A\$1:D\$278,IF(MOD(NOW(),1)<"20:00"+0,2,4),0)

Replies
1
Views
139
Replies
34
Views
976
Replies
3
Views
3K
Replies
10
Views
541
Replies
2
Views
468

1,221,521
Messages
6,160,302
Members
451,637
Latest member
hvp2262

### 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.

### Which adblocker are you using?

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

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