XL2010 Need Sub to Stop if the Active Sheet is a Copy

Klevins11

New Member
Joined
May 15, 2015
Messages
6
I created a minor prank and I would like to add a little more safety to it. The process starts with making copies of the sheets in your workbook and hides them. Then it randomly selects cells in the used range of the active sheet and deletes the contents. This is set on a timer. I really would like to add something to stop the sub if the user decides to unhide a copy. I'm not sure how to differentiate between a copy and an original. Perhaps stopping could be linked to the act of unhiding and not the particular active sheet. For better understanding this is what I have...
Code:
'Start when workbook is openedSub auto_open()
Call copy_hide
End Sub

'Copy all worksheets and hide the copy
Sub copy_hide()
Dim x As Integer

For x = 1 To ActiveWorkbook.Sheets.Count 'Begin loop through workbook
   ActiveWorkbook.Sheets(x).Copy _
   After:=ActiveWorkbook.Sheets(ActiveWorkbook.Sheets.Count) 'Copy active worsheet
   ActiveWorkbook.ActiveSheet.Visible = False 'Hide copied worksheet
Next
   
   ActiveWorkbook.Sheets(1).Activate 'Activate first sheet
Call repeat_time
End Sub

'Set a repeat time
Sub repeat_time()
    TimeToRun = Now + TimeValue("00:00:01") 'Run random_clear() every 3 seconds
    Application.OnTime TimeToRun, "random_clear"
End Sub

'Select and clear contents of a random cell(within used range of active worksheet)
Sub random_clear()
Dim y As Integer
Dim x As Integer
Dim row_min As Integer
Dim row_max As Integer
Dim col_min As Integer
Dim col_max As Integer

    row_min = ActiveSheet.UsedRange.row 'Return numerical values for range of used cells
    row_max = row_min + ActiveSheet.UsedRange.Rows.Count - 1
    col_min = ActiveSheet.UsedRange.Column
    col_max = col_min + ActiveSheet.UsedRange.Columns.Count - 1

    Randomize                                 'Pick a random number from the used range
    y = Int((row_max - row_min + 1) * Rnd + row_min)
    Randomize
    x = Int((col_max - col_min + 1) * Rnd + col_min)

    ActiveSheet.Cells(y, x).Select 'Enter random number and return a selected cell
    Selection.ClearContents 'Clear contents of selected cell

Call repeat_time
End Sub
I need something at the end with logic like: If ActiveSheet = copy, end sub, If Not , continue
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).

Forum statistics

Threads
1,203,461
Messages
6,055,559
Members
444,799
Latest member
CraigCrowhurst

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