I've been using this code in so many spreadsheets with me since it's a template. But whenever I change the sheetname, the VBA won't work.
1. Can someone please help me how to make this vba work even when sheetname is changed? And..
2. How do I make another VBA button that when clicked would copy the spreadsheet without going through the WRITE CLICK>MOVE OR COPY>CLICK TO COPY procedure using the mouse?
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Or Target.HasFormula Then Exit Sub
On Error Resume Next
If Not Intersect(Target, Range("b14:B131")) Is Nothing Then
Application.EnableEvents = False
Target = UCase(Target)
Application.EnableEvents = True
End If
On Error GoTo 0
End Sub
Sub HideRow()
Dim lLastRow As Long
Dim lCounter As Long
ActiveSheet.Unprotect
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Application.EnableEvents = False
Sheets("SF 1").Shapes("Button 1").Visible = False
With Worksheets("SF 1") 'Change to suit
lLastRow = .Range("ar65536").End(xlUp).Row
For lCounter = 14 To lLastRow
If .Cells(lCounter, "ar").Value = 1 Then
.Cells(lCounter, "ar").EntireRow.Hidden = True
'Else: .Cells(lCounter, "ar").EntireRow.Hidden = False
End If
Next lCounter
.Range("A14").Select
End With
Sheets("SF 1").Shapes("Button 2").Visible = True
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub
Sub UnHideRow()
ActiveSheet.Unprotect
Worksheets("SF 1").Rows.Hidden = False
Sheets("SF 1").Shapes("Button 1").Visible = True
Sheets("SF 1").Shapes("Button 2").Visible = False
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub
Bookmarks