Hide Unhide Rows Macro Crashes

mjb342

New Member
Joined
May 3, 2020
Messages
9
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I have the following code that was working before but now crashes and instantly closes the excel workbook whenever I click the button to run. I use the same macro on multiple sheets. Basically, if three cells added together equal zero I write "Hide" in the cell in column "O". The macro then hides all rows with "Hide" in column O. Not sure what happened to all of a sudden make this not work.

Thank you in advance for any thoughts.

VBA Code:
Option Explicit
Sub HideRows()
Dim i As Long, LR As Long
LR = Range("O" & Rows.Count).End(xlUp).Row
For i = 1 To LR
    If Range("O" & i).Value = "Hide" Then
        Rows(i).Hidden = True
    Else
        Rows(i).Hidden = False
    End If
Next i

End Sub


Sub UnhideRows()
    
   Rows("1:500").EntireRow.Hidden = False

End Sub
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

mjb342

New Member
Joined
May 3, 2020
Messages
9
Office Version
  1. 365
Platform
  1. Windows
I moved the code to the individual sheets I need it on and removed the macro. Seems to work now.
 

Watch MrExcel Video

Forum statistics

Threads
1,129,284
Messages
5,635,305
Members
416,851
Latest member
zeldadav

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
Top