Slow vba code

Even

Board Regular
Joined
Jan 1, 2013
Messages
81
Office Version
  1. 365
Platform
  1. Windows
Hi, this code is very slow, and I don't know why. It is a dropdown list in B1. And whenever I choose a name, it takes long time to calculate. Anybody?

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim i As Integer

Application.ScreenUpdating = False
If Not Application.Intersect(Range("B1"), Range(Target.Address)) Is Nothing Then
    Select Case Target.Value
    
    Case Is = "Text":
        For i = 3 To 500
            If Range("AK" & i).Value = "Text" Then
            Rows(i).EntireRow.Hidden = False
            Else: Rows(i).EntireRow.Hidden = True
        End If

    Next i
    
    Case Is = "Text":
        For i = 3 To 500
            If Range("AK" & i).Value = "Text" Then
            Rows(i).EntireRow.Hidden = False
            Else: Rows(i).EntireRow.Hidden = True
        End If
        
        
    
        Application.ScreenUpdating = True

 End Select

    
End Sub
 
Okay - I am working on it :)

By the way - it takes approx. 3.33 sec for each calculation. It is not super duper slow, but still kind of annoying.
 
Upvote 0

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Okay, here is a shot at answering your questions:
- How many values are you really looking for?
* What I am actually finding is names of my colleagues. There are four of us and we divide all our customers among ourselves. As of today, there are around 350 customers, however, the list is growing. The dropdown list in "B1" is to select one of our names, and the result should be that all the customers per the chosen colleague's name is displayed.
- Are these values hard-coded (always the same), or are they coming from somewhere else?
* Yes, the four of us are the constant factor.
- How many rows of data do you really have? One way to limit the number of rows you have to loop through is to dynamically find the last row of data, i.e.
* We have around 350 rows, but that is constantly changing.

The last code I have is just to unhide all rows.
 
Upvote 0

Hi, just use some Excel basics feature like a filter for example in order to get an instant result obviously …​
 
Upvote 0
I agree with you, Marc. But I don't know how to incorporate that into my model. It consists of a couple of macros that I am afraid will be affected by it. I also have some bad experience having auto filter meaning it filtered some and not others.
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,868
Members
449,053
Latest member
Mesh

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
Back
Top