วิธีสร้างลูปภายในลูปใน VBA อย่างมีประสิทธิภาพมากขึ้น

For iiii = 2 To RLast

For v = 2 To Last2

    If ws2.Cells(v, 7) = ws3.Cells(iiii, 1) Then
        If ws2.Cells(v, 1) <> "FLHIGH" And ws2.Cells(v, 1) <> "VLOWER" Then
            AmountCount2 = AmountCount2 + ws2.Cells(v, 8)
            AmountCount = ws2.Cells(v, 9)
            Coun = 1
            Crit1 = ws2.Cells(v, 5)
        Else
            If Cranes(Locat, Forbidden, Forbidden2, Forbidden3, Forbidden4, Forbidden5) = False Then
                If Coun = 0 Then
                    AmountCount = AmountCount + (ws2.Cells(v, 8) + ws2.Cells(v, 9))
                    Crit2 = ws2.Cells(v, 5)
                    Coun = 1
                Else
                    AmountCount = AmountCount + (ws2.Cells(v, 8))
                    Crit2 = ws2.Cells(v, 5)
                End If
            Else 
                AmountCount = ws2.Cells(v, 9)
                Crit2 = ws2.Cells(v, 5)
            End If
        End If
    End If
    ws3.Cells(iiii, 4) = AmountCount 
    ws3.Cells(iiii, 5) = AmountCount2 
Next v

Next iiii
Dim srCount As Long: srCount = Last2 - 1
Dim srg As Range: Set srg = ws2.Rows(2).Columns("A:I").Resize(srCount)
Dim sData As Variant: sData = srg.Value

Dim drCount As Long: drCount = RLast - 1
Dim drg As Range: Set drg = ws3.Rows(2).Columns("A:E").Resize(drCount)
Dim dlData As Variant: dlData = drg.Columns("A").Value
Dim dvrg As Range: dvrg = drg.Columns("D:E")
Dim dvData As Variant: dvData = dvrg.Value

Dim sr As Long
Dim dr As Long

For dr = 1 To drCount
    For sr = 1 To srCount
        If sData(sr, 7) = dlData(dr, 1) Then
            If sData(sr, 1) <> "FLHIGH" And sData(sr, 1) <> "VLOWER" Then
                AmountCount2 = AmountCount2 + sData(sr, 8)
                AmountCount = sData(sr, 9)
                Coun = 1
                Crit1 = sData(sr, 5)
            Else
                If Cranes(Locat, Forbidden, Forbidden2, Forbidden3, _
                        Forbidden4, Forbidden5) = False Then
                    If Coun = 0 Then
                        AmountCount = AmountCount + sData(sr, 8) _
                            + sData(sr, 9)
                        Crit2 = sData(sr, 5)
                        Coun = 1
                    Else
                        AmountCount = AmountCount + sData(sr, 8)
                        Crit2 = sData(sr, 5)
                    End If
                Else
                    AmountCount = sData(sr, 9)
                    Crit2 = sData(sr, 5)
                End If
            End If
        End If
    Next sr

    dvData(dr, 1) = AmountCount
    dvData(dr, 2) = AmountCount2

Next dr

dvrg.Value = dvData