Consulting

Results 1 to 4 of 4

Thread: ActiveX button VBA references contents of button sheet even after activating new one

  1. #1

    ActiveX button VBA references contents of button sheet even after activating new one

    I have some very simple code that works with a regular macro button but not an ActiveX button. I just activate a different sheet and select range A1. Selecting range A1 produces "Select method of Range class failed" error. I found through some debugging that it's looking at the A1 on the sheet where the button resides, not the one that has just been activated. This seems to be a real problem. How can I work around this? Again, identical code is fine with standard macro button. Code:

    Private Sub CheckInCycle_Click()
        Sheet25.Activate
        Range("A1").Select
    End Sub

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    Reference a routine in a Module when using that method in a sheet's Private sub. Note that activating and selecting are seldom needed to achieve most goals.

  3. #3
    Aha, forgot about that when programming in sheet modules. Thanks!

  4. #4
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    In a worksheet module, any unqualified range reference refers to that sheet, not the active one, so you just need to specify:
    Private Sub CheckInCycle_Click()    With Sheet25
           .Activate
           .Range("A1").Select
        End With
    End Sub
    Be as you wish to seem

Posting Permissions

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