Adding or subtracting minutes from Now in VBA Code

Harold R.

Board Regular
Joined
Sep 26, 2004
Messages
132
I have the following code and it works great it was given to me by some of the board members. Is ther a way to insert additional language in it that will add minutes to the Now time. Also the same in reverse is there language that will Subtract minutes from the Now? I know nothing about code but I am trying to learn. The following is the code:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Intersect(Target, Union(Range("B9:B44"), Range("D9:D44"), Range("F9:F44"), Range("H9:H44"), Range("J9:J44"), Range("K9:K44"))) Is Nothing Then Exit Sub
If Selection.Rows.Count > 1 Then Exit Sub
If Selection.Value <> "" Then Exit Sub
With Selection
.Value = Now
.NumberFormat = "hh:mm"
End With
End Sub
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Thanks that worked great. How would I seperate it out I want to subtract minutes from B9:B44 Only and the I want to add 1 minute to H9:H44. Is that difficult to do given the code I have?
 
Upvote 0

Forum statistics

Threads
1,214,426
Messages
6,119,411
Members
448,894
Latest member
spenstar

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