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...
I need something at the end with logic like: If ActiveSheet = copy, end sub, If Not , continue
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