Code execution is extremly slow

dvaladas

New Member
Joined
Nov 30, 2016
Messages
33
Hi,
Can someone help me with this code?
Everthing is working fine but the execution is too slow.
There is anyway to improve it?
Thanks in advance.

Code:
Sub AlocaçãoTarefas()
 
    lastrow = Worksheets("Inputs Pendentes").Cells(Rows.Count, 2).End(xlUp).Row
    fim = Worksheets("Input Regras").Cells(Rows.Count, 2).End(xlUp).Row
    
    For RowPendentes = 22 To lastrow
        For RowRegra = 16 To fim
            If Worksheets("Inputs Pendentes").Cells(RowPendentes, 33).Value = "" Then 'Verify if there is already an employee assigned to the task
                If Worksheets("Inputs Pendentes").Cells(RowPendentes, 31).Value = "Não" Then ' Verify if the task has already been assigned
                    If Worksheets("Inputs Pendentes").Cells(RowPendentes, 32).Value = Worksheets("Input Regras").Cells(RowRegra, 7).Value Then ' Verify if the task ID matches the employee ID
                        If Worksheets("Input Regras").Cells(RowRegra, 10).Value < Worksheets("Input Regras").Cells(RowRegra, 9).Value Then ' Verify if the employee’s capacity to solve tasks is full
                           Worksheets("Inputs Pendentes").Cells(RowPendentes, 33).Value = Worksheets("Input Regras").Cells(RowRegra, 2).Value ' Fill column W from sheet Input Pendentes with the employee’s name assigned to the task
                           RowRegra = fim 'Indication to stop covering allocation rules
                        Else
                        End If
                    Else
                    End If
                Else
                End If
            Else
            End If
        Next RowRegra
    Next RowPendentes
  
End Sub
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Try this one:
Code:
Sub AlocaçãoTarefas()
Dim lastrow As Long, fim As Long, RowPendentes As Long, RowRegra As Long
Dim arrPendentes As Variant, arrRegras As Variant

lastrow = Worksheets("Inputs Pendentes").Cells(Rows.Count, 2).End(xlUp).Row
fim = Worksheets("Input Regras").Cells(Rows.Count, 2).End(xlUp).Row

arrPendentes = Worksheets("Inputs Pendentes").Range("AE22:AG" & lastrow)
arrRegras = Worksheets("Input Regras").Range("G16:J" & fim)

For RowPendentes = 1 To lastrow - 21
    For RowRegra = 1 To fim - 15
        If arrPendentes(RowPendentes, 3) = "" Then 'Verify if there is already an employee assigned to the task
            If arrPendentes(RowPendentes, 1) = "Não" Then ' Verify if the task has already been assigned
                If arrPendentes(RowPendentes, 2) = arrRegras(RowRegra, 1) Then ' Verify if the task ID matches the employee ID
                    If arrRegras(RowRegra, 4) < arrRegras(RowRegra, 3) Then ' Verify if the employee’s capacity to solve tasks is full
                       Worksheets("Inputs Pendentes").Cells(RowPendentes + 21, 33).Value = Worksheets("Input Regras").Cells(RowRegra + 15, 2).Value ' Fill column W from sheet Input Pendentes with the employee’s name assigned to the task
                       Exit For 'Indication to stop covering allocation rules
                    End If
                End If
            End If
        End If
    Next RowRegra
Next RowPendentes
End Sub
 
Last edited:
Upvote 0
Cross-posted: Code execution is extremly slow

While we do not prohibit Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule #13 here along with the explanation: Forum Rules). This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.
 
Upvote 0
I'm sorry but I do not understand what you mean by "alocation capacity by person"...?

It seems that this part of the code isn't doing nothing once that I have an employee with capicity of 60 and with 900 tasks alocated to him

If arrRegras(RowRegra, 4) < arrRegras(RowRegra, 3) Then ' Verify if the employee’s capacity to solve tasks is full
 
Upvote 0
Sorry, I was not sure about the rules. How can I edit the post?
I already added the link in my reply. Just be sure to do so in the future.

Thanks
 
Upvote 0

Forum statistics

Threads
1,214,784
Messages
6,121,540
Members
449,038
Latest member
Guest1337

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