ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   optimizing code? (hide) (https://www.excelbanter.com/excel-programming/317576-optimizing-code-hide.html)

Johan Johansson

optimizing code? (hide)
 
I have a drop-down list from where the user can select which day he
wants to see.

At first I hide everything, after that I run the little procedure
below

The problem that I'm having is that this takes lots of time running
this. How do I change the procedure so it will run faster?

Sub show_days()

Dim compare
Application.ScreenUpdating = False

compare = Range("F10").Value

Range("F13").Select

For n = 1 To 8000
ActiveCell.Offset(1, 0).Select
If ActiveCell.Value = compare Then
ActiveCell.EntireRow.Hidden = False
End If
Next n

Application.ScreenUpdating = True

End Sub

/Johan

Chip Pearson

optimizing code? (hide)
 
Johan,

There is no reason to Select or Activate a cell within the loop.
Instead, try something like

For N = 13 To 8013
If Cells(N,"F").Value = compare Then
Rows(N).Delete
End If
Next N


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"Johan Johansson" wrote in message
m...
I have a drop-down list from where the user can select which day
he
wants to see.

At first I hide everything, after that I run the little
procedure
below

The problem that I'm having is that this takes lots of time
running
this. How do I change the procedure so it will run faster?

Sub show_days()

Dim compare
Application.ScreenUpdating = False

compare = Range("F10").Value

Range("F13").Select

For n = 1 To 8000
ActiveCell.Offset(1, 0).Select
If ActiveCell.Value = compare Then
ActiveCell.EntireRow.Hidden = False
End If
Next n

Application.ScreenUpdating = True

End Sub

/Johan




Chip Pearson

optimizing code? (hide)
 
Rows(N).Delete

should be
Rows(N).Hidden = False


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Chip Pearson" wrote in message
...
Johan,

There is no reason to Select or Activate a cell within the
loop. Instead, try something like

For N = 13 To 8013
If Cells(N,"F").Value = compare Then
Rows(N).Delete
End If
Next N


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"Johan Johansson" wrote in message
m...
I have a drop-down list from where the user can select which
day he
wants to see.

At first I hide everything, after that I run the little
procedure
below

The problem that I'm having is that this takes lots of time
running
this. How do I change the procedure so it will run faster?

Sub show_days()

Dim compare
Application.ScreenUpdating = False

compare = Range("F10").Value

Range("F13").Select

For n = 1 To 8000
ActiveCell.Offset(1, 0).Select
If ActiveCell.Value = compare Then
ActiveCell.EntireRow.Hidden = False
End If
Next n

Application.ScreenUpdating = True

End Sub

/Johan







All times are GMT +1. The time now is 12:05 PM.

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