Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I ended up rewriting a lot of your code to make it more efficient, this should accomplish what you're looking for, and it should run rather quickly also:</p> <pre><code>Sub Extract() Dim cllProjects As Collection Dim wsData As Worksheet Dim wsEnha As Worksheet Dim wsOver As Worksheet Dim rngFind As Range Dim rngFound As Range Dim rngProject As Range Dim arrProjects() As Variant Dim varProjectType As Variant Dim ProjectIndex As Long Dim cIndex As Long Dim dRVal As Double Dim dRDate As Double Dim strFirst As String Dim strProjectFirst As String Dim strProject As String Set wsData = Sheets("AllData") Set wsEnha = Sheets("Enhancements") Set wsOver = Sheets("Overheads") wsEnha.Range("B4:O" &amp; Rows.Count).ClearContents wsOver.Range("B4:O" &amp; Rows.Count).ClearContents With wsData.Range("E4", wsData.Cells(Rows.Count, "E").End(xlUp)) If .Row &lt; 4 Then Exit Sub 'No data On Error Resume Next For Each varProjectType In Array("Enhancements", "OVH") Set cllProjects = New Collection ProjectIndex = 0 ReDim arrProjects(1 To WorksheetFunction.CountIf(.Cells, "*" &amp; varProjectType &amp; "*"), 1 To 14) Set rngFound = .Find(varProjectType, .Cells(.Cells.Count), xlValues, xlPart) If Not rngFound Is Nothing Then strFirst = rngFound.Address Do strProject = vbNullString dRDate = wsData.Cells(rngFound.Row, "H").Value2 dRVal = wsData.Cells(rngFound.Row, "I").Value2 If varProjectType = "OVH" And dRVal &gt; 0 Then strProject = wsData.Cells(rngFound.Row, "D").Text Set rngFind = Intersect(.EntireRow, wsData.Columns("D")) ElseIf varProjectType = "Enhancements" Then strProject = wsData.Cells(rngFound.Row, "E").Text Set rngFind = .Cells End If If Len(strProject) &gt; 0 Then cllProjects.Add LCase(strProject), LCase(strProject) If cllProjects.Count &gt; ProjectIndex Then ProjectIndex = cllProjects.Count arrProjects(ProjectIndex, 1) = strProject Set rngProject = Intersect(rngFound.EntireRow, Columns(rngFind.Column)) strProjectFirst = rngProject.Address Do If LCase(rngProject.Text) = LCase(strProject) Then dRDate = wsData.Cells(rngProject.Row, "H").Value2 dRVal = wsData.Cells(rngProject.Row, "I").Value2 cIndex = Month(dRDate) - 2 + (Year(dRDate) - 2013) * 12 arrProjects(ProjectIndex, cIndex) = arrProjects(ProjectIndex, cIndex) + dRVal End If Set rngProject = rngFind.Find(arrProjects(ProjectIndex, 1), rngProject, xlValues, xlPart) Loop While rngProject.Address &lt;&gt; strProjectFirst End If End If Set rngFound = .Find(varProjectType, rngFound, xlValues, xlPart) Loop While rngFound.Address &lt;&gt; strFirst End If If cllProjects.Count &gt; 0 Then Select Case varProjectType Case "Enhancements": wsEnha.Range("B4").Resize(cllProjects.Count, UBound(arrProjects, 2)).Value = arrProjects Case "OVH": wsOver.Range("B4").Resize(cllProjects.Count, UBound(arrProjects, 2)).Value = arrProjects End Select Set cllProjects = Nothing End If Next varProjectType On Error GoTo 0 End With Set cllProjects = Nothing Set wsData = Nothing Set wsEnha = Nothing Set wsOver = Nothing Set rngFound = Nothing Set rngProject = Nothing Erase arrProjects End Sub </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload