Find nearest time to NOW()

JeffGrant

Well-known Member
Joined
Apr 7, 2021
Messages
516
Office Version
  1. 365
Platform
  1. Windows
Hi All,

To find the nearest time in a range to the current time i am using =Now() in a cell, then using copy/paste special value to "fix" the current time, so that I can find the nearest next time to Now.

I don't believe I can the NOW function in a SMALL or Index/Match formula because NOW is always increasing.

Can anybody suggest a better way to do this because I like to avoid using the Clipboard if I can?

Thanks
 

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.
Here is a VBA Solution:

VBA Code:
Sub PasteNow()
'
' PasteNow Macro
'

'
    ActiveCell.FormulaR1C1 = "=NOW()"
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
End Sub
 
Upvote 0
Hi

not sure if this would work, but what about using LET(Tim,now(),try your formula here)

I‘m wondering if by setting Tim to be Now() if you can then use it in the formula after without it changing ?

just a thought
Rob
 
Upvote 0
Here is a user defined function.

Create a module in VBA (Alt-F11, Insert Module) Paste this code;
VBA Code:
Function PNow()
Dim x As Variant
x = Now
PNow = x
End Function

Then Click: Debug, Compile VBAProject
then go back to your worksheet, and type =PNow in any cell.
Hit enter,
You'll need to format the cell for Date and Time.

I believe it will only recalculate when you recalculate the Cell itself or a cell using the UDF. It will not recalculate when pressing F9. I am not sure if it will recalculate when re-opening the workbook.
 
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,954
Members
449,095
Latest member
nmaske

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