Macro that disables itself one executed? HELP please

Caveman1964

Board Regular
Joined
Dec 14, 2017
Messages
127
Office Version
  1. 2016
Platform
  1. Windows
Hi,
I would like to run a macro, and it disables itself when ran.

here is code.
Sub enterstopdown()
Range("D6").Value = Now()
End Sub

so when they click this and it enters the date and time, I don't want that one to work anymore.
Thanks!
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
is the macro called from a button or other object ? if so, then before the end sub, you could disable the object, so they can't click it again


If it is called from within a Worksheet.SelectionChange Event then i guess you could check to see if there is a value in the cell before proceeding to enter the date time
 
Upvote 0
How about
Code:
Sub enterstopdown()
If Range("D6") <> "" Then Exit Sub
 Range("D6").Value = Now()
 End Sub
If there is already something in D6 the code will not execute.
 
Upvote 0
Ah I see that will work.
Also, if you have time, could that one macro button select the next one down and Enter date time?
Thanks for the time!
 
Upvote 0
How about
Code:
Sub enterstopdown()
If Range("D6") <> "" Then Exit Sub
 Range("D6").Value = Now()
 End Sub
If there is already something in D6 the code will not execute.

Yes this works perfect! thanks
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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