ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Hide Rows meeting condition Amendment (https://www.excelbanter.com/excel-programming/349693-hide-rows-meeting-condition-amendment.html)

Robert

Hide Rows meeting condition Amendment
 
Can some one amend the following code to substitute 2 to 10000 to a named range
"CondRange" (for condition range)
--
Dim i%, rng As Range
Set rng = Sheets("Staff").Cells(1, 2)
For i = 2 To 1000
If Sheets("Staff").Cells(i, 2) = "X" Then
Set rng = Union(rng, Sheets("Staff").Cells(i, 2))
End If
Next i
rng.Rows.EntireRow.Hidden = True
End Sub
(original code by Alok Joshi)

Thank you, Robert

Norman Jones

Hide Rows meeting condition Amendment
 
Hi Robert,

Try:

Sub Tester()
Dim i As Long
Dim rng As Range
Dim rng2 As Range
Dim SH As Worksheet

Set SH = Sheets("Staff")

With SH
Set rng = .Cells(1, 2)
Set rng2 = .Range("CondRange")

For i = 2 To rng2.Rows.Count
If .Cells(i, 2).Value = "X" Then
Set rng = Union(rng, .Cells(i, 2))
End If
Next i
rng.Rows.EntireRow.Hidden = True
End With

End Sub
'<<==============

---
Regards,
Norman


"Robert" wrote in message
...
Can some one amend the following code to substitute 2 to 10000 to a named
range
"CondRange" (for condition range)
--
Dim i%, rng As Range
Set rng = Sheets("Staff").Cells(1, 2)
For i = 2 To 1000
If Sheets("Staff").Cells(i, 2) = "X" Then
Set rng = Union(rng, Sheets("Staff").Cells(i, 2))
End If
Next i
rng.Rows.EntireRow.Hidden = True
End Sub
(original code by Alok Joshi)

Thank you, Robert




Robert

Hide Rows meeting condition Amendment
 
Thank you Norman. Using the range name is superfast. Never expected this way.
--
Robert





All times are GMT +1. The time now is 08:37 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com