Back Forum Reply New

Add code for keyboard ESC button into macro

Hello,

Is there a code to put in a macro that tells the macro to press the 'Esc' button twice?

The reason for this is I have a current macro and if a text box is selected when the macro is ran... it duplicates the text box a bunch of times. If there is a code for pressing the 'Esc' button a couple times, then the macro would de-select the text box (if it's highlighted) and run the macro properly.

~Thanks

What is the macro code - there are almost certainly better ways, such as checking the type of the selection first.
Regards,
Rory

It may not even be necessary to select.

First off... I got a lot of these codes from online websites as my knowledge of programming macros is a beginner unless I'm using the macro recorder.

I'm using the following code in several cells to randomize several columns which contain data...

=INDIRECT("L"amp;INT(RAND()*(380-1)+1))
=INDIRECT("M"amp;INT(RAND()*(107-1)+1))

and the following code is attached to the same sheet in the VBA area...

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address  "$E$12" Then Exit Sub
name1.Value = Target.Value
End Sub

So now when I press or hold Control+D it will run the randomization on several cells using the data given in several different columns.

Then I created a macro and linked it to a button, so when the user presses the button it runs the macro. This macro is nothing more a recorded 'control + D' about 20 times. Sub start()
'   Application.Run "'Randomizer 2.0.xls'!limit_range"   Selection.FillDown   Selection.FillDown   Selection.FillDown   Etc....
End SubSo overall it randomizes several cells a bunch of times using data from a couple of different columns.  

Now I have added text input boxes and I'm also turning the protection ON on the sheet so no user can tamper with any coding. They can only input text using the text boxes. However, if they press the macro-linked button while one of these text boxes is still selected (which the macro is nothing more than control+d) it will duplicate the text boxes about 20 times.

So I am wondering if there is a coding that is VBA for the 'escape button' which will be used to exit the text input boxes before it runs control+D as bunch of times. It would de-select the text boxes and then finish running the coding.

I hope I explained this easy and any help would be appreciated.

Actually, i figured out a solution. Sorry for any trouble.
¥
Back Forum Reply New