Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    Dec 2001
    Posts
    174
    Thanks
    0
    Thanked 0 Times in 0 Posts

    commandbutton1_click (2003)

    Hi all -- need some help
    I am trying to assign a macro to a commandbutton1_click
    The macro contains a loop which writes a value to certain cells however the the moment I write to a cell the macro seems to exit (no debugging just exists) as if writing to a cell is some sort of event which causes the macro to exit --hope I made my problem clear
    thanx
    Smbs

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: commandbutton1_click (2003)

    Without knowing what your code does, and whether you have worksheet level or workbook level event procedures, it's hard to say.

    Does it work better if you structure the code like this?

    Private Sub CommandButton1_Click()
    On Error GoTo ErrHandler
    Application.EnableEvents = False

    ' Your code goes here
    ...

    ExitHandler:
    Application.EnableEvents = True
    Exit Sub

    ErrHandler:
    MsgBox Err.Description, vbExclamation
    Resume ExitHandler
    End Sub

  3. #3
    2 Star Lounger
    Join Date
    Dec 2001
    Posts
    174
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: commandbutton1_click (2003)

    Hans---thanx for quick reply and code
    Have just got home from work and the macro runs just fine on my home computer so here might be a problem with my computer at work.............
    Once again many thanx for your error trapping code
    Regards
    Smbs

Posting Permissions

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