Sub CleanitUp2(): Dim wp As Worksheet, wa As Worksheet, WF As WorksheetFunction, D
Dim r As Long, c As Long, i As Long, j As Long, k As Long, T As String, DP As String
Set WF = WorksheetFunction
Set wp = Sheets("Adherence Data Paste"): Set wa = Sheets("Adherence ")
wp.Cells.WrapText = False: wp.Cells.MergeCells = False: wp.Columns.AutoFit
r = wp.Rows.Find("*", , , , xlByRows, xlPrevious).Row
c = wp.Columns.Find("*", , , , xlByColumns, xlPrevious).Column
wp.Rows(1).Insert: Set D = wp.Rows(1)
For i = 1 To r + 1
If WF.CountA(wp.Rows(i)) = 0 Then _
Set D = Union(D, wp.Rows(i))
Next i: i = 1
D.EntireRow.Delete
GetTable: k = WF.MAX(1, wa.Rows.Find("*", , , , xlByRows, xlPrevious).Row)
Do Until wp.Cells(i, 3) = "Agent Adherence Totals Report": i = i + 1
If i > r Then
'wp.Cells.Clear
Exit Sub: End If
Loop: T = wp.Cells(i + 3, 10)
j = i: Do Until InStr(1, LCase(wp.Cells(j, 6)), "wfm reports"): j = j + 1: Loop
If InStr(1, LCase(T), "none") Or T = "" Then
wp.Range("A" & i & ":A" & j).EntireRow.Delete Shift:=xlUp
r = wp.Rows.Find("*", , , , xlByRows, xlPrevious).Row: GoTo GetTable: End If
i = i + 5
ExtractEntries:
k = k + 1: DP = wp.Cells(i, 4)
Do: i = i + 1
If wp.Cells(i, 5) <> "" And wp.Cells(i, 5) <> "Agent" Then
wa.Cells(k, 1) = DP: wa.Cells(k, 2) = T
wa.Cells(k, 3) = wp.Cells(i, 5): wa.Cells(k, 4) = wp.Cells(i - 1, 15)
wa.Cells(k, 5) = wp.Cells(i - 1, 17): wa.Cells(k, 6) = wp.Cells(i - 1, 20)
wa.Cells(k, 7) = wp.Cells(i, 24): k = k + 1
End If
Loop Until IsDate(wp.Cells(i, 4)) Or i = j
If i = j Then GoTo GetTable
k = k - 1: GoTo ExtractEntries
End Sub
Bookmarks