my code activates when ever i do something in another cell

deadfishsurfer

New Member
Joined
Mar 12, 2015
Messages
6
Hi
I am using a 2 codes that i had modded for me:
the first is

Sub Button3_Click()
Dim i As Long
For i = 9 To 18
Range("B7" & i) = RND()
Next i

End Sub

the second one is

Sub myRnd()




Dim myOrder As Range
Dim myName
Dim mySelect As Variant
Randomize


mySelect = Int((19 * RND) + 1)


myName = Range("J" & mySelect)




Worksheets("Sheet1").Range("B4") = myName


End Sub


it all works fine, i click the button and it all goes fine
but after the random data is generated whenever i edit, or leave any other cell the code runs again without any prompt changing the random data to new random data
how can i adjust this so it will only happen when the button is clicked ?

Hope someone can help
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
do you have worksheet_activate or worksheet_selectionchange events set on the sheet you are working with
 
Upvote 0
Workbook_Sheet Activate

In the Modules i only have general and declarations
do i need to move the code into the sheet?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,419
Messages
6,124,796
Members
449,189
Latest member
kristinh

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