Code help

Damo10

Active Member
Joined
Dec 13, 2010
Messages
460
Hi,

I have some basic code to hide some rows in my sheet, this loop takes some time to complete.
Can anyone help me with some code that will work faster?

Code:
Sub Hide()
Dim i As Integer
Application.ScreenUpdating = False
For i = 18 To 1120
    Cells(i, 2).Select
    If Cells(i, 2).Value = 1 Then Selection.EntireRow.Hidden = True
Next i
Range("E20").Select
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Try

Code:
Sub Hide()
Dim i As Integer
Application.ScreenUpdating = False
For i = 18 To 1120
    Rows(i).Hidden = Cells(i, 2).Value = 1
Next i
Application.ScreenUpdating = True
End Sub
 
Upvote 0
HI VOG,


Could the code be modified so that if the number of rows expands the code will repeat until it finds the last row that is populated?
I am checking if there is a 1 in any row in column B to hide the row

Thanks for your help
 
Upvote 0
Try

Code:
Sub Hide()
Dim i As Integer
Application.ScreenUpdating = False
For i = 18 To Range("B" & Rows.Count).End(xlUp).Row
    Rows(i).Hidden = Cells(i, 2).Value = 1
Next i
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,584
Messages
6,179,687
Members
452,938
Latest member
babeneker

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