Macro Causes Excel to Not Respond - but works in another file?

BLerro

New Member
Joined
Sep 13, 2016
Messages
4
Hi all,

I've got a macro that runs through cells in a column and if the cell value is "HIDE" then it hides that entire row and if the cell is "Show" it ignores that row and continues until it finds another "HIDE" or to the first blank cell.

For someone reason it works in another file of mine but in the current file I'm using it causes excel to crash/not respond.

Any thoughts? It's an old macro I've had for a while so I'm sure it can use some updating.

Code:
Sub Hide_Rows()
'
    Dim strCurrentCell As String
    Dim strCurrentSheet As String
    strCurrentCell = ActiveCell.Address
    strCurrentSheet = ActiveSheet.Name
    Dim Calc_Setting As Long
    Dim endrng As String
    Dim Srtrng As String
    Calc_Setting = Application.Calculation
    Application.Calculation = xlCalculationManual
    Application.ScreenUpdating = False
    On Error Resume Next
    ActiveSheet.Unprotect Password:="password"
    Cells.Select
    ActiveSheet.Outline.ShowLevels RowLevels:=2
    Selection.Rows.Ungroup
    Range("AM:AN").Select
    Selection.EntireColumn.Hidden = False
    Range("AN1").Select
    On Error Resume Next
    Do
      If ActiveCell = "HIDE" Then
      Srtrng = ActiveCell.Address
      Cells.Find(What:="Show", After:=ActiveCell, LookIn:=xlValues, LookAt:= _
        xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
        False, SearchFormat:=False).Activate
      ActiveCell.Offset(-1, 0).Select
      endrng = ActiveCell.Address
      Range(Srtrng, endrng).Select
      Selection.Rows.Group
      Range(endrng).Select
      ActiveCell.Offset(1, 0).Select
      End If
      
      If ActiveCell = "Show" Then
      ActiveCell.Offset(1, 0).Select
      End If
      
    Loop Until ActiveCell = ""
    ActiveSheet.Outline.ShowLevels RowLevels:=1, ColumnLevels:=0


    Range("AM:AN").Select
    Selection.EntireColumn.Hidden = True
    ActiveSheet.Protect Password:="password", DrawingObjects:=True, Contents:=True, Scenarios:=True _
        , AllowFormattingCells:=True, AllowFormattingColumns:=True, AllowFormattingRows:=True, AllowFiltering:=True
    Sheets(strCurrentSheet).Select
    Range(strCurrentCell).Select
    Range("B9").Select
    Application.ScreenUpdating = True
    Application.Calculation = Calc_Setting
End Sub
Thanks,
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
UPDATE - for some reason it only crashes when there is no "Show" below that last "HIDE". It's as if the part of the code to determine if the active cell is blank and to stop is not working.
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,875
Members
452,363
Latest member
merico17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top