View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
[email protected] gimme_this_gimme_that@yahoo.com is offline
external usenet poster
 
Posts: 129
Default Fast way to make rows visible and invisible

This turned out to be what I needed ...

Note that there is a limit to about 30 rows to how many rows can be
selected at once using this syntax..

Range(x1:x1,x2:x2...").Select




Public Sub RegionView(sheet As Worksheet, NavigationColumn As Long)
Dim i As Integer, j As Integer
Dim rowType As String, hideRows As String, showRows As String
hideRows = ""
showRows = ""
Dim LastRow As Integer
LastRow = sheet.Cells(rows.Count, "A").End(xlUp).Row
' set all cells to visible
sheet.Cells.EntireRow.Hidden = False

j = 0
For i = STARTING_ROW_INDEX To LastRow
rowType = sheet.Cells(i, NavigationColumn).Value

If "br_branch" = rowType Then
j = j + 1
hideRows = hideRows + CStr(i) + ":" + CStr(i) + ","
ElseIf "br_target" = rowType Then
j = j + 1
hideRows = hideRows + CStr(i) + ":" + CStr(i) + ","
ElseIf "rg_region" = rowType Then
j = j + 1
hideRows = hideRows + CStr(i) + ":" + CStr(i) + ","
End If


' Excel returns a 400 error if more than 30 rows are hidden at a time
If j 30 Then
hideRows = Left(hideRows, Len(hideRows) - 1)
sheet.Range(hideRows).EntireRow.Hidden = True
j = 0
hideRows = ""
End If

Next i
hideRows = Left(hideRows, Len(hideRows) - 1)
sheet.Range(hideRows).EntireRow.Hidden = True

End Sub