Excel running slow

pijan11

New Member
Joined
Jan 29, 2022
Messages
29
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hello,

I'm new to VBA and I need some help with speed being slow when inputing data into my file (sorry for my data being in French). When I input data in the Fields entitled "École", "Année scolaire", i can't do anything for about 4 seconds. When I input data into the field "Nombre d'élèves", and I click on the big yellow button to get to another sheet (2nd mini sheet) then the number of lines showing should match the number inputed on the first sheet by using this code (I have another similar sheet using the same code that is password locked which you can access by clicking on the left green button on mini sheet 1, but this sheet is running a little faster) and the some formulas in the sheet itself (see below)

CODE

VBA Code:
Private Sub Worksheet_Calculate()
       
    Dim c As Range
        
    Application.EnableEvents = False
    
    
        For Each c In Range("A11:A110") '<====Input your range here
        
            If c.Value = "" Then
                Rows(c.Row & ":" & c.Row).EntireRow.Hidden = True
            Else
                Range(c.Row & ":" & c.Row).EntireRow.Hidden = False
            End If
            
        Next

    Application.EnableEvents = True

End Sub

Formula
=IFERROR(IF(Accueil!E13="","",1),"")
=IFERROR(IF(A11+1>Accueil!E$13,"",Ecole!A11+1),"")

where "Ecole" is the active sheet (mini sheet 2) and "Accueil!E$13" is the cell I inputed the numbre 5 in mini sheet 1

I then manually input data in the other columns in mini sheet 2 and here is where it gets really slow, about 15 seconds before I can click in another cell.

I must say that the data inputed into mini sheet 2 is beeing copied to 3 other sheets.

Any help would be appreciated

Mini sheet 1

Écoles élémentaires - Dotation AE 2021-2022.xlsm
BCDEFGHIJKLMN
8
9
10École:Année scolaire:
11
12
13Nombre d'élèves: 5
14
15
16Nom de la personne ou des personnes qui ont contribués aux données fournies dans ce fichier:
17
18
19
20
21
22
Accueil
Cells with Data Validation
CellAllowCriteria
H10:H14List= Année
C10:E10List= Écoles
E13List= Nombre


Mini sheet 2

Écoles élémentaires - Dotation AE 2021-2022.xlsm
BCDEFGHIJKLMN
8
9
10École:Année scolaire:
11
12
13Nombre d'élèves: 5
14
15
16Nom de la personne ou des personnes qui ont contribués aux données fournies dans ce fichier:
17
18
19
20
21
22
Accueil
Cells with Data Validation
CellAllowCriteria
H10:H14List= Année
C10:E10List= Écoles
E13List= Nombre
 
Thanks for including the extra information and showing the workbook events.
I was a bit concerned about the protection but somewhat surprisingly having the protection "on" did not stop it from working.

Can you confirm that on the Ecole sheet that the number 1 appears in Cell A11 and that your formula in column A returns ""
if the row number is > than what you have in E13 ?

I prefer using debug.print but are you more comfortable with having a message box ?
In the worksheet_change module BEFORE the "End If" can you add this line:
VBA Code:
        MsgBox "Performed the Worksheet Events"

In the HideShowRows module, just BEFORE the "End SUB" can you add this line:-
VBA Code:
    MsgBox "Sheet= " & sht.Name & vbLf & "rngHide= " & rnghide.Address & vbLf & "rngShow= " & rngshow.Address
OK......I included a mini sheet so you can see what is in cell A11 and added the extra line in the 2 codes but nothing is happening.

Silly question: When I'm in visual basic can I run the HideShowRows ? Cause If I try to run it I don't see it in the list (see image below)
Screen Shot 2022-01-31 at 11.09.52 PM.png


Demo.xlsm
ABCDEFGH
9Nom de l'élèveAnnée d'étude AnomalieHoraire personnalisé (retrait partiel de la classe <50%)Est-ce que l'élève est à l'école à temps partiel ?PEIConditions grave
10ex: Prénom Nom6e annéeAssociéesNonNonOuiTrouble du langage, TSA
111
122
133
144
155
166
177
188
199
2010
2111
2212
23 
24 
25 
26 
27 
28 
29 
30 
31 
32 
Ecole
Cell Formulas
RangeFormula
C9C9="Année d'étude " &Accueil!$H$10
A11A11=IFERROR(IF(Accueil!E13="","",1),"")
A12:A32A12=IFERROR(IF(A11+1>Accueil!E$13,"",Ecole!A11+1),"")
Cells with Data Validation
CellAllowCriteria
C11:C110List= Niveau
D11:D110List= Anomalies
E11:G110List= OuiNon
 
Upvote 0

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Thanks for including the extra information and showing the workbook events.
I was a bit concerned about the protection but somewhat surprisingly having the protection "on" did not stop it from working.

Can you confirm that on the Ecole sheet that the number 1 appears in Cell A11 and that your formula in column A returns ""
if the row number is > than what you have in E13 ?

I prefer using debug.print but are you more comfortable with having a message box ?
In the worksheet_change module BEFORE the "End If" can you add this line:
VBA Code:
        MsgBox "Performed the Worksheet Events"

In the HideShowRows module, just BEFORE the "End SUB" can you add this line:-
VBA Code:
    MsgBox "Sheet= " & sht.Name & vbLf & "rngHide= " & rnghide.Address & vbLf & "rngShow= " & rngshow.Address
CORRECTION......I just tried it on a windows pc and it is working......I was working on a mac so not sure why it is not working on mac
 
Upvote 0
Thanks for including the extra information and showing the workbook events.
I was a bit concerned about the protection but somewhat surprisingly having the protection "on" did not stop it from working.

Can you confirm that on the Ecole sheet that the number 1 appears in Cell A11 and that your formula in column A returns ""
if the row number is > than what you have in E13 ?

I prefer using debug.print but are you more comfortable with having a message box ?
In the worksheet_change module BEFORE the "End If" can you add this line:
VBA Code:
        MsgBox "Performed the Worksheet Events"

In the HideShowRows module, just BEFORE the "End SUB" can you add this line:-
VBA Code:
    MsgBox "Sheet= " & sht.Name & vbLf & "rngHide= " & rnghide.Address & vbLf & "rngShow= " & rngshow.Address
So now my last question is how to we get it to work without having a message box?
 
Upvote 0
The message box does not affect the operation of the macro, so just delete the 2 msgbox lines.
ie the one in the Worksheet_Change module and
the one in the HideSheet module. (unless you think you might need them again then just comment them out by putting a single quote (') in front of the line)

Did it resolve the speed issue ?
 
Upvote 0
The message box does not affect the operation of the macro, so just delete the 2 msgbox lines.
ie the one in the Worksheet_Change module and
the one in the HideSheet module. (unless you think you might need them again then just comment them out by putting a single quote (') in front of the line)

Did it resolve the speed issue ?
I was able to test it once and the speed was fine. But now i'm trying to test it again and i'm getting this error

Screen Shot 2022-02-01 at 12.26.30 AM.png


If I click on Debug, this is what I get from the code in module:

Screen Shot 2022-02-01 at 12.27.41 AM.png
 
Upvote 0
Change both the lines in your screenshot to this:
VBA Code:
    If Not rnghide Is Nothing Then rnghide.EntireRow.Hidden = True
    If Not rngshow Is Nothing Then rngshow.EntireRow.Hidden = False
 
Upvote 0
Change both the lines in your screenshot to this:
VBA Code:
    If Not rnghide Is Nothing Then rnghide.EntireRow.Hidden = True
    If Not rngshow Is Nothing Then rngshow.EntireRow.Hidden = False
i'm still getting the error message
 
Upvote 0
Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: Excel running slow due to macros
If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0
Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: Excel running slow due to macros
If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
Thank you for letting me know......I was unaware. No valid solution was provided on other forums so I did go to the other forums and added a link to this one. I was in a crunch to present my file to my employer so this is why I posted in different forums. It's noted. But I am glad to say that this is where I found the most help. Thanks MrExcel
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,728
Members
448,987
Latest member
marion_davis

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