I've developed a macro to cleanup sets of copy/pasted data that is just a series of rows into an Excel with multiple columns and headers. To help clean the data I've added three FOR LOOP processes to:
- Delete the rows that were numbered bullets
- Deleted data that was extraneous (miles & minActive)
- Manually cut/paste the other dataset into their respective columns (steps & stepavg)
It seems to work well however I'd like to optimize the process. While running the macro, the issue is that I used "UsedRange" to figure out how many rows are present for FOR LOOP 1 (approx 800 rows). During that loops, many rows are deleted so it may filter from 800 to 350. Then when FOR LOOP 2 is performed, it seems like UsedRange is still reference 800 rows so the loop just continues, which filters from 350 to 65. Finally with FOR LOOP 3, it crunches and completes all 65 successfully and I can tell that its done. BUT, it'll keep going to row 800!
Any suggestions to "clear" or "reset" the UsedRange so this process is faster? Other than this issue, my macro works great.
'Cleaning the Data
    Dim i As Long
    Dim j As Long
    Dim k As Long
    Dim maxRow As Long
    maxRow = ActiveSheet.UsedRange.Rows.Count
    'Removes all those single number rows
    For i = 2 To maxRow Step 3
        Rows(i).Select
        Selection.Delete Shift:=xlLeft
    Next i
    Range("A1").Select
    'Removes all those miles and min active data
    Dim maxRow2 As Long
    maxRow2 = ActiveSheet.UsedRange.Rows.Count
    For j = 5 To maxRow2 Step 3
        Range(Rows(j), Rows(j + 5)).Select
        Selection.Delete Shift:=x1Up
    Next j
    Range("A1").Select
    'Cut/paste the Steps and StepsAvg data
    Dim maxRow3 As Long
    maxRow3 = ActiveSheet.UsedRange.Rows.Count
    For k = 3 To maxRow Step 1
        Cells(k, 1).Select
        Selection.Cut
        Cells(k - 1, 2).Select
        ActiveSheet.Paste
        Cells(k + 1, 1).Select
        Selection.Cut
        Cells(k - 1, 3).Select
        ActiveSheet.Paste
        Range(Rows(k), Rows(k + 1)).Select
        Selection.Delete Shift:=x1Up
    Next k
 
     
    