problem to visible tab code

  • The code below is making the sheet (in my case is "Main") to be visible and placed near the sheet you currently select. The Problem is that the code can interfere in the running of other macro. I noticed that when the macro run and comes to select particular sheet and then copy cells from that sheet to another, the debug window will pop up as the below code was interfere by cancelling the copy as it always activate or select "Main" sheet or tab before you select the sheet and paste cells to the sheet. Can you make the code below possible not to interrupt in the running of other macro like in my case above?

    The code is:


    Code
    Private Sub Workbook_SheetActivate(ByVal Sh As Object)
    If Not Sh Is Worksheets("Main") Then
    Application.EnableEvents = False
    Worksheets("Main").Move before:=Sh
    Sh.Activate
    Application.EnableEvents = True
    End If
    End Sub


    Thanks in advance

  • Welcome to the Forum. Please read the Forum Rules to understand how the Forum works and why I have added Code Tags to your post


    All VBA code posted in the forum must be wrapped in code tags, which you omitted, including single-line code snippets.Be sure to use them in future posts.


    How to use code tags


    Just highlight all of the code and press the <> in the post menu above button to add the code tags.


    Thanks.

  • You don't usually need to activate or select sheets. Try removing that line or attach an example of the workbook and explain what you need to do.


    Read the Forum Rules first.

  • Thanks Roy,


    attached is the example of what happened in my case:


    The code above or below was in Thisworkbook of the VBA. when you run the macro under the command button in the "Main" sheet, There will be an error that I thought caused by the code below.


    Thank you so much and waiting for your solution


    Code
    Private Sub Workbook_SheetActivate(ByVal Sh As Object)
    If Not Sh Is Worksheets("Main") Then
    Application.EnableEvents = False
    Worksheets("Main").Move before:=Sh
    Sh.Activate
    Application.EnableEvents = True
    End If
    End Sub

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!