Hello Folks,

I have an issue happening with my macro. Here is what it is supposed to do:

I have lots of data in a spreadsheet related to different nodes for a 30 day time period. Each node has 3-4 parts. My macro is supposed to take each part and list it in a separate spreadsheet and place the corresponding data for each of the day and place an average of it at the end of the row.

The problem I am having is that my macro does this thirty times even though I have a filter subroutine built in which is supposed to discard (not redo) any values which have already been worked on. Here is my code:

Sub Filter1()
'
' Filter1 Macro
'
'
Dim i As Integer
Dim j As Integer
Dim site1 As String
Dim rng1 As Range
Dim Lastrow As Long
Dim k As Integer
Dim l As Integer
Dim flag As Integer

Application.ScreenUpdating = False

Sheets("Filter_Calc").Cells.Clear
Sheets("Report").Cells.Clear
Sheets("Site_Check1").Cells.Clear

i = 2
j = 1
k = 2
l = 1

Sheets("All_Data").Select
Do While Cells(i, 1) <> ""
    Sheets("Filter_Calc").Cells.Clear
    Sheets("All_Data").Select
    site1 = Cells(i, 1).Value
'    The part that isnt doing its job starts here
    Sheets("Site_Check1").Select
    If Cells(1, 1).Value = "" Then
        Cells(1, 1).Value = site1
    Else
        l = 1
        Do While Cells(l, 1).Value <> ""
            If site1 = Cells(l, 1).Value Then
                flag = 1
            Else
                flag = 0
            End If
            l = l + 1
        Loop
        Cells(l, 1).Value = site1
    End If
'   and sort of ends here. The rest can or cannot be considerd part of the issue as the flag value tests to make sure that the site hasnt already been used.
    If flag <> 1 Then
        Sheets("All_Data").Select
        ActiveSheet.Range("$A$1:$U$80531").AutoFilter Field:=1, Criteria1:=site1
        Range("A1:E80343").Select
        Selection.Copy
        Sheets("Filter_Calc").Select
        Cells(1, 1).Select
        ActiveSheet.Paste
        Sheets("All_Data").Select
        ActiveSheet.Range("$A$1:$U$80531").AutoFilter Field:=1
        Sheets("Filter_Calc").Select
        Cells.Select
        Cells.EntireColumn.AutoFit
        Range("A1").Select
        Columns("A:A").ColumnWidth = 16#
        Columns("B:B").ColumnWidth = 16#
        Columns("C:C").ColumnWidth = 16#
        Columns("D:D").ColumnWidth = 16#
        Columns("E:E").ColumnWidth = 16#
        Cells.Select
        Cells.EntireRow.AutoFit
        Cells.EntireColumn.AutoFit
        Lastrow = Range("E" & Rows.count).End(xlUp).Row
        Range("E" & Lastrow + 1).Formula = "=AVERAGE(" & Range("E2:E" & Lastrow).Address(0, 0) & ")"
'copying data from main sheet and tranposing onto new sheet for calculation
        If i = 2 Then
            Sheets("Filter_Calc").Select
            Range("B2").Select
            Range(Selection, Selection.End(xlDown)).Select
            Selection.Copy
            Sheets("Report").Select
            Range("B1").Select
            Range("B1").Select
            Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
                False, Transpose:=True
        End If
        Sheets("Filter_Calc").Select
        Range("E2").Select
        Range(Selection, Selection.End(xlDown)).Select
        Selection.Copy
        Sheets("Report").Select
        If Cells(k, 2).Value = "" Then
            Cells(k, 1).Value = site1
            Cells(k, 2).Select
            Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
                False, Transpose:=True
            k = k + 1
        Else
            k = k + 1
        End If
    End If
    i = i + 1
    Sheets("All_Data").Select
Loop
Application.ScreenUpdating = True
MsgBox ("Raw Values Arranged")

End Sub
Any assistance would be highly appreciated.

Thanks.