Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bad performance after color count

I have a problem with bad performance after implementing this code into my Excel list to count the filled cells without a color in the set range:

Function CountCcolor(range_data As Range, criteria As Range) As Long
    Dim datax As Range
    Dim xcolor As Long
    xcolor = criteria.Interior.ColorIndex
    For Each datax In range_data
        If datax.Interior.ColorIndex = xcolor And Not datax.Value = vbNullString Then
           CountCcolor = CountCcolor + 1
        End If
    Next datax
End Function

I use this one as well to count yellow and red cells on the same page in the set range, but it doesn't lower the performance as much as the one above:

Function Farbsumme(Bereich As Range, Farbe As Integer)
    Dim Zelle As Range
    Application.Volatile
    For Each Zelle In Bereich
        If Zelle.Interior.ColorIndex = Farbe Then
            Farbsumme = Farbsumme + 1
        End If
    Next
End Function

Is there something I did wrong? Anything I could do better to increase the performance?

like image 814
Psychosun Avatar asked Aug 20 '18 07:08

Psychosun


People also ask

Why am I getting low FPS all of a sudden?

The most common reason for reduced FPS is graphics settings that create a larger workload than your hardware can handle. So how do you achieve better FPS? Getting a faster CPU, more RAM, or a newer graphics card is one solution.

Why do I have low FPS with good PC?

What is a low FPS and what causes it? Low FPS, or frames per second, is when your game slows down because your computer doesn't have enough power or memory to run it properly. Common causes of low FPS are a weak graphics card, old graphics drivers, an outdated CPU, or insufficient RAM.

Why is FPS so low?

Low frames-per-second (FPS) rates, or frame rates in games are usually caused by computer hardware not being able to meet a game's system requirements at a given setting. If a device's hardware and a game's requirements are too far apart, a game will refuse to load.

Can CPU affect FPS?

Your CPU will always affect your in-game FPS because, as explained above, it's heavily involved in so many aspects of game processing. However, certain factors change how relevant the CPU is to your FPS. For one, while most games are very GPU intensive, some are CPU intensive.


1 Answers

You might be using the other function in your sheet and every time it recalculates the application.volatile slows down your code.

Removing application.volatile might solve your problem.

like image 174
Imran Malek Avatar answered Oct 04 '22 07:10

Imran Malek