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

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
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,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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