Results 1 to 33 of 33

Macro operated by button clears worksheet but not executed successfully automatically

Threaded View

  1. #1
    Forum Contributor
    Join Date
    11-08-2014
    Location
    UK
    MS-Off Ver
    Office 2013
    Posts
    208

    Macro operated by button clears worksheet but not executed successfully automatically

    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?
    Last edited by ThiaJay; 08-06-2020 at 05:33 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] strange behaviour from vba
    By harryv27 in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 04-14-2016, 04:50 AM
  2. [SOLVED] XIRR strange behaviour
    By phe in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-06-2013, 01:51 AM
  3. Strange Behaviour
    By Mark@Work in forum Excel General
    Replies: 2
    Last Post: 09-30-2008, 12:22 PM
  4. [SOLVED] Strange if(***) behaviour?
    By Excel 2003 - SPB in forum Excel General
    Replies: 6
    Last Post: 08-06-2006, 12:35 PM
  5. Strange VBA Behaviour
    By Ricko in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-28-2005, 03:05 AM
  6. Very strange add-in file behaviour
    By RB Smissaert in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 05-18-2005, 02:45 PM
  7. [SOLVED] Strange behaviour
    By Edgar Thoemmes in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-08-2005, 12:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1