Run-once macro

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi All...........
Is there a way to have a SelectionChange macro set up so it will run the
first time it's called upon, and as a last item, disable itself to never run
again unless "reset"?

TIA
Vaya con Dios,
Chuck, CABGx3
 
You could have the macro, as the first step, check what ever unique
condition it imposes and if it appears it has run, then exit.

It will still run, but will exit without doing anything.
 
There are probably a number of ways, but I would get it to create a Name
(hidden) with a particular reference when it runs. Then, at the start of the
SelectionChange event you could look at the name to see the value and run it
or not based on that.

Jeff
 
Chuck,

Try something like


Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim Res As Variant
On Error Resume Next
Res = ThisWorkbook.Names("RunOnce").Value
If IsEmpty(Res) Then
MsgBox "Run Once Code"
End If
ThisWorkbook.Names.Add "RunOnce", "TRUE"

End Sub

You can reset it by deleting the name "RunOnce"

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
Cool........that should work for my immediate requirement.........

Thanks, Tom

Vaya con Dios,
Chuck, CABGx3
 
Back
Top