Find nearest time to NOW()

JeffGrant

Well-known Member
Joined
Apr 7, 2021
Messages
558
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

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
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,224,609
Messages
6,179,875
Members
452,949
Latest member
Dupuhini

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