Hide Unhide Rows Macro Crashes

mjb342

New Member
Joined
May 3, 2020
Messages
11
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

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
I moved the code to the individual sheets I need it on and removed the macro. Seems to work now.
 
Upvote 0

Forum statistics

Threads
1,214,661
Messages
6,120,796
Members
448,994
Latest member
rohitsomani

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