I have assigned a macro to a button that will operate once. It is creating an estimate number using date, customer last name and a random number. Once it has run, subsequent presses of the button do generate the Already Run message which is what I was trying to do. I need to be able to run it once for every time the Buyer Last Name (Cell F11) changes, in other words when someone begins a new estimate the button (and macro) should operate once. Not sure how to pull that one off. Any thoughts would be appreciated.
I have the macro button assigned to the following macro
This works well but if the last name is changed I'd like it to be able to run again.
I tried adding this line just below Option Explicit thinking if the cell was changed it would reset and got an error stating that the variable Target.Address is not defined.
If Target.Address = "$F$11" Then HasRun = False
Thanks much
Bill
I have the macro button assigned to the following macro
Code:
Option Explicit
Sub capture_cell_value()
'Copy Estimate number once from hidden and protected cell
Static HasRun As Boolean
If HasRun = True Then Exit Sub 'If the macro has run exit
MsgBox "Already run!", vbExclamation 'message to screen
Range("F10").Copy
Range("F14").Select
Range("F14").NumberFormat = "General"
Range("F14").Font.Bold = True
Range("F14").Font.Color = vbRed
End Sub
This works well but if the last name is changed I'd like it to be able to run again.
I tried adding this line just below Option Explicit thinking if the cell was changed it would reset and got an error stating that the variable Target.Address is not defined.
If Target.Address = "$F$11" Then HasRun = False
Thanks much
Bill