Robert1985

New Member
Joined
Jul 6, 2017
Messages
3
Hi,

I have created a macro (below) to search a range and hide rows with no value, however, on running the macro it takes around a minute to run.
Is there anyway this can be sped up?

Dim xRg As Range
Application.ScreenUpdating = False
For Each xRg In Range("D1:D105")
If xRg.Value = "" Then
xRg.EntireRow.Hidden = True

Else
xRg.EntireRow.Hidden = False
End If
Next

End Sub


Thanks,
 

Some videos you may like

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

steve the fish

Well-known Member
Joined
Oct 20, 2009
Messages
8,256
Office Version
  1. 365
Platform
  1. Windows
See if this is any quicker:

Code:
Dim xRg As Range, rng As Range, rngHide As Range, rngVis As Range
Dim arr, myVal as Long, i As Long

With Application
    .ScreenUpdating = False
    .Calculation = xlCalculationManual
End With

Set rng = Range("D1:D105")
myVal = rng.Cells(1).Row
arr = rng
  
For i = LBound(arr, 1) To UBound(arr, 1)
    Select Case Len(arr(i, 1))
        Case 0
            If Not rngHide Is Nothing Then
                Set rngHide = Union(rngHide, Rows(i + myVal - 1))
            Else
                Set rngHide = Rows(i + myVal - 1)
            End If
        Case Is > 0
            If Not rngVis Is Nothing Then
                Set rngVis = Union(rngVis, Rows(i + myVal - 1))
            Else
                Set rngVis = Rows(i + myVal - 1)
            End If
    End Select
Next
If Not rngHide Is Nothing Then rngHide.EntireRow.Hidden = True
If Not rngVis Is Nothing Then rngVis.EntireRow.Hidden = False

With Application
    .ScreenUpdating = True
    .Calculation = xlCalculationAutomatic
End With
 

Watch MrExcel Video

Forum statistics

Threads
1,122,628
Messages
5,597,247
Members
414,133
Latest member
lucid33

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