Macro to execute all worksheets with one exception

I am trying to write a macro that selects any lines with text in a specific column (it does not matter which text), and then insert it into the summary sheet, for this I need to iterate over all the sheets in the workbook panel, Summary sheet. However, I have problems with its operation, I continue to get "Compile Error: Method or Data Member not Found", I need the macro to look through all the sheets, regardless of the name, since the sheets are eventually archived and new ones added.

Now I have changed the way the macro finds cells with text in below, I do not know if this will change the situation:

Sub SmartCopy ()

Dim s1 As Worksheet, s2 As Worksheet
Dim N As Long, i As Long, j As Long
Set s1 = Sheets("Customer 1")
Set s2 = Sheets("Action Summary")
N = s1.Cells(Rows.Count, "C").End(xlUp).Row
j = 2
For i = 6 To N
    If s1.Cells(i, "C").Value = "" Then
    Else
        s1.Cells(i, "C").EntireRow.Copy s2.Cells(j, 1)
        j = j + 1
    End If
Next i

End Sub

I'm new to this and probably totally wrong, but any help would be appreciated.

+1
1

STOP .Select

-, . , , .

Sub TestIt()

Dim wsheet As Worksheet

For i = 1 To ThisWorkbook.Worksheets.Count
    If ThisWorkbook.Worksheets(i).Name <> "Action Summary" Then 'And ThisWorkbook.Worksheets(i).Name <> "Another Exception" And ...
        Set wsheet = ThisWorkbook.Worksheets(i)
        For j = 6 to wsheet.Range("A" & Rows.Count).End(xlUp).Row
            If Not wsheet.Range("C" & j).Value = "" Then
                wsheet.Range("C" & j).EntireRow.Copy
                Sheets("Action Summary").Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValues
            End If
        Next j
    End If
Next i

End Sub
+1

Source: https://habr.com/ru/post/1693404/


All Articles