+ Reply to Thread
Results 1 to 1 of 1

COPY SHEET FUNCTION works solely but with other VBA proceeds error.

Hybrid View

  1. #1
    Forum Contributor wedzmer's Avatar
    Join Date
    06-13-2014
    Location
    Philippines
    MS-Off Ver
    2016
    Posts
    422

    COPY SHEET FUNCTION works solely but with other VBA proceeds error.

    Badly need help here...

    I wanted to combine these functions with one worksheet.

    First: I have a dual function VBA for Hiding and Unhiding Rows & Columns.
    Second: I also single function COPY SHEET button.

    Both buttons work perfectly when not combined in one sheet. The situations I have observed are:

    When the COPY SHEET BUTTON is clicked and there is a new sheet now, ALL THE BUTTONS on this new sheet are not working...

    Here is the original VBA Code that presents error:

    Sub HideRow()
    Dim lLastRow As Long
    Dim lCounter As Long
    Dim Rng As Range
    Dim Counter As Boolean
    Counter = True
    
        Application.ScreenUpdating = False
        Application.Calculation = xlCalculationManual
        Application.EnableEvents = False
        
        With ActiveSheet
        
            .Unprotect ("09193483966")
            .Shapes("Button 1").Visible = False
    
    For Each CL In Range("HM200:KO200")
    If CL.Value = 1 Then
        If Counter Then
            Set Rng = CL
            Counter = False
        Else
            Set Rng = Union(Rng, CL)
        End If
    End If
    Next CL
    Rng.EntireColumn.Hidden = True
    
    
           lLastRow = .Range("E1000").End(xlUp).Row
            For lCounter = 14 To lLastRow
                If .Cells(lCounter, "E").Value = 1 Then
                    .Cells(lCounter, "E").EntireRow.Hidden = True
                    'Else: .Cells(lCounter, "GM").EntireRow.Hidden = False
                End If
            Next lCounter
            .Range("G12").Select
    
            .Shapes("Button 2").Visible = True
        End With
    
        Application.EnableEvents = True
        Application.Calculation = xlCalculationAutomatic
        Application.ScreenUpdating = True
    
        ActiveSheet.Protect ("09193483966"), DrawingObjects:=True, Contents:=True, Scenarios:=True
    
    End Sub
    
    Sub UnHideRow()
    
        With ActiveSheet
            .Unprotect ("09193483966")
            .Rows.Hidden = False
            .Columns.Hidden = False
            .Range("A:F").Columns.Hidden = True
            .Shapes("Button 1").Visible = True
            .Shapes("Button 2").Visible = False
            .Protect ("09193483966"), DrawingObjects:=True, Contents:=True, Scenarios:=True
        
        End With
        
    End Sub
    
    Private Sub Worksheet_Change(ByVal Target As Range)
    
       If Target.Cells.Count > 1 Then Exit Sub
       
       Application.EnableEvents = False
       
       On Error GoTo ErrH
       If Target.Address = "$AN$7" Then
           Me.Name = Target
           Application.EnableEvents = True
           Exit Sub
       End If
       
       If Not Intersect(Target, Range("b12:B131")) Is Nothing Then
           Target = UCase(Target)
       End If
       
       Application.EnableEvents = True
       Exit Sub
       
    ErrH:
       MsgBox "Invalid Worksheet Name"
       Application.EnableEvents = True
       
    End Sub
    
    Sub CopySheet()
        ActiveSheet.Copy After:=ActiveSheet
    End Sub
    and here is the file I'm working on.. if there is any password being asked, please use "09193483966".

    Academic Teacher ECR.xlsm

    Thanks for anyone who would like to help...


    ===========
    MODERATOR's NOTE: This question crossposted here.
    Last edited by JBeaucaire; 06-27-2015 at 08:19 PM. Reason: Added crosspost link. Please read and follow the forum rules, link above in the menu bar. Thanks.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] .Match with On Error: On Error Resume Next works. On Error GoTo only works once. Err.Clear
    By Doc.AElstein in forum Excel - New Users/Basics
    Replies: 28
    Last Post: 03-16-2015, 12:55 PM
  2. Function works but I get a run time error 13.
    By Rob K in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-20-2014, 04:41 AM
  3. Replies: 13
    Last Post: 04-08-2014, 05:46 AM
  4. Formula to copy data to new sheet works but gives an error when run
    By bm1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-12-2010, 03:34 PM
  5. simple copy column works but ERROR!
    By Jack in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-30-2005, 02:00 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