PDA

View Full Version : Reversing a Macro



josephm
06-04-2008, 05:14 AM
I have used the following code to delete duplicates thanks to DRJ.


Sub MyMacro3()
With Sheet2
.Unprotect Password:="Secret"
Dim x As Long
Dim LastRow As Long

LastRow = .Range("A" & .Rows.Count).End(xlUp).Row
For x = LastRow To 1 Step -1
If Application.CountIf(.Range("A1:A" & x), .Range("A" & x).Text) > 1 Then
.Rows(x).Delete
End If
Next x
.Protect Password:="Secret", UserInterFaceOnly:=True
End With
End Sub

now i want to use two macros one to hide one to unhide.

so i was wondering if i could use the same code with the following code change to achieve this.

The macro MyMacro1 is to hide:


Sub MyMacro1()
With Sheet2
.Unprotect Password:="Secret"
Dim x As Long
Dim LastRow As Long

LastRow = .Range("A" & .Rows.Count).End(xlUp).Row
For x = LastRow To 1 Step -1
If Application.CountIf(.Range("A1:A" & x), .Range("A" & x).Text) > 1 Then
.Rows(x).Hide
End If
Next x
.Protect Password:="Secret", UserInterFaceOnly:=True
End With
End Sub

The macro MyMacro2 is to unhide

Sub MyMacro2()
With Sheet2
.Unprotect Password:="Secret"
Dim x As Long
Dim LastRow As Long

LastRow = .Range("A" & .Rows.Count).End(xlUp).Row
For x = LastRow To 1 Step -1
If Application.CountIf(.Range("A1:A" & x), .Range("A" & x).Text) > 1 Then
.Rows(x).Unhide
End If
Next x
.Protect Password:="Secret", UserInterFaceOnly:=True
End With
End Sub
~Code Tags Added By Oorang

Bob Phillips
06-04-2008, 05:50 AM
.Rows(x).Hidden = True/False