I have a macro that runs when I click a button on a worksheet to clear the contents. It works without fault.
Sub Reset1()
'
' Reset1 Macro
'
'
Worksheets("Search").Range("A1").Clear
Worksheets("Search").Range("A3:L1500").Clear
Worksheets("Search").Range("A3:A1500").HorizontalAlignment = xlCenter
Worksheets("Search").Range("A3:A1500").VerticalAlignment = xlCenter
Worksheets("Search").Pictures.Delete
Worksheets("Search").Range("A1").Select
End Sub
I want it to also run when the worksheet is opened so that other users don't see the data when they open it up and it's empty, ready for them to use.
So I tried to introduce code into the worksheet.
Sub Auto_Open()
Worksheets("Search").Range("A1").Clear
Worksheets("Search").Range("A3:L1500").Clear
Worksheets("Search").Range("A3:A1500").HorizontalAlignment = xlCenter
Worksheets("Search").Range("A3:A1500").VerticalAlignment = xlCenter
Worksheets("Search").Pictures.Delete
Worksheets("Search").Range("A1").Select
End Sub
or
Sub Worksheet_Activate()
Worksheets("Search").Range("A1").Clear
Worksheets("Search").Range("A3:L1500").Clear
Worksheets("Search").Range("A3:A1500").HorizontalAlignment = xlCenter
Worksheets("Search").Range("A3:A1500").VerticalAlignment = xlCenter
Worksheets("Search").Pictures.Delete
Worksheets("Search").Range("A1").Select
End Sub
It does remove most of the data, but there are still SOME cells in column i and I don't understand why this is?
If I click on the button and run the same code after the worksheet is opened, it clears the remaining cells (as it should). If I test the code in Microsoft Visual Basic for Applications, it runs without fault?
Bookmarks