Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 129
Default Fast way to make rows visible and invisible


My application has the following Sub which hides some rows and makes
others visible :

Is there a way to speed up this code somehow so that the cells are set
to visible and invisible in two instructions.

The code is real slow.

Public Sub RegionView(sheet As Worksheet, NavigationColumn As Long)
Dim i As Integer
Dim rowType As String
For i = STARTING_ROW_INDEX To MAXIMUM_ROW_INDEX
rowType = sheet.Cells(i, NavigationColumn).Value
If i < 2 Then
MsgBox rowType
End If
If "br_br" = rowType Then
sheet.Rows(CStr(i) + ":" + CStr(i)).EntireRow.Hidden = True
ElseIf "br_ta" = rowType Then
sheet.Rows(CStr(i) + ":" + CStr(i)).EntireRow.Hidden = True
ElseIf "rg_rg" = rowType Then
sheet.Rows(CStr(i) + ":" + CStr(i)).EntireRow.Hidden = True
ElseIf "rg_tr" = rowType Then
sheet.Rows(CStr(i) + ":" + CStr(i)).EntireRow.Hidden = False
Else
sheet.Rows(CStr(i) + ":" + CStr(i)).EntireRow.Hidden = False
End If
If i MAXIMUM_ROW_INDEX Then
Exit For
End If
Next i
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,073
Default Fast way to make rows visible and invisible

Hi,
Turning off screenupdating should speed things up (you'll still see
your msgbox)
Application.ScreenUpdating = False added at the start is enough for
that (it's automatically turned back on when the code finishes)
Rows(CStr(i) + ":" + CStr(i)).EntireRow.Hidden = True can be reduced
to
Rows(i).EntireRow.Hidden = True which reduces the number of vb
functions used and should therefore speed things up as well.
Ken Johnson

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 129
Default Fast way to make rows visible and invisible

Thanks Ken.

I used your tip.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,073
Default Fast way to make rows visible and invisible

Hi,
Thanks for the feedback. Hope you're getting reasonable speed now.
ScreenUpdating usually makes a signifcant difference when the code is
changing the active sheet.
Ken Johnson

  #5   Report Post  
Posted to microsoft.public.excel.programming
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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Make a chart axis visible/invisible with VBA Jeff Reese Charts and Charting in Excel 3 April 27th 23 03:42 AM
change invisible bars back to visible hf Charts and Charting in Excel 1 July 28th 06 02:29 PM
Check Box to switch make comments visible or invisible DanHegarty Excel Discussion (Misc queries) 1 June 10th 06 04:08 PM
invisible text boxes becoming visible Jordan Excel Programming 1 February 26th 05 12:01 AM
How do I make a command button invisible or visible? Mandora Excel Programming 3 February 17th 05 08:40 PM


All times are GMT +1. The time now is 08:59 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"