Merging two loops of array together

cortexnotion

Board Regular
Joined
Jan 22, 2020
Messages
150
Office Version
  1. 2013
Platform
  1. Windows
Hi All

I am looping in an array to get the total figures and then another loop to individual figures which makes the code rather long. I was wondering if the Tech loop could be incorporated into the main loop?

Below is an extract from my code:

Many thanks!

VBA Code:
d = 1
If CDShtAry(e, 3) >= LW2 And CDShtAry(e, 3) <= LW1 And CDShtAry(e, 4) = "Completed" Then
        If CDShtAry(e, 15) <= CDSLA Then
            CompAry(d, 11) = CompAry(d, 11) + 1
            CompAry(d, 12) = CompAry(d, 12) + CDShtAry(e, 11)
            CompAry(d, 13) = CompAry(d, 13) + CDShtAry(e, 12)
        ElseIf CDShtAry(e, 15) > CDSLA Then
            CompAry(d, 14) = CompAry(d, 14) + 1
            CompAry(d, 15) = CompAry(d, 15) + CDShtAry(e, 11)
            CompAry(d, 16) = CompAry(d, 16) + CDShtAry(e, 12)
        End If
        CompAry(d, 17) = CompAry(d, 17) + CDShtAry(e, 14)
        CompAry(d, 18) = 0
    End If
Next e
d = 2
For Each Tech In TechAry
    For f = LBound(CDShtAry) To UBound(CDShtAry)
        CompAry(d, 1) = LW1
        CompAry(d, 2) = Tech
        If CDShtAry(f, 3) >= LW2 And CDShtAry(f, 3) <= LW1 And CDShtAry(f, 4) = "Completed" And CDShtAry(f, 5) = Tech Then
            If CDShtAry(f, 15) <= CDSLA Then
                CompAry(d, 11) = CompAry(d, 11) + 1
                CompAry(d, 12) = CompAry(d, 12) + CDShtAry(f, 11)
                CompAry(d, 13) = CompAry(d, 13) + CDShtAry(f, 12)
            ElseIf CDShtAry(f, 15) > CDSLA Then
                CompAry(d, 14) = CompAry(d, 14) + 1
                CompAry(d, 15) = CompAry(d, 15) + CDShtAry(f, 11)
                CompAry(d, 16) = CompAry(d, 16) + CDShtAry(f, 12)
            End If
            CompAry(d, 17) = CompAry(d, 17) + CDShtAry(f, 14)
            CompAry(d, 18) = 0
        End If
    Next f
    d = d + 1
Next Tech
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

Forum statistics

Threads
1,215,221
Messages
6,123,699
Members
449,117
Latest member
Aaagu

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