I have been following this forum for several weeks and I have found many answers here, for which I thank you very much! I would also like to contribute in the future.
But now he has this question that I can't handle.
How omit sheets from the loop?
I want to skip copying tables from sheets named "Data" and "Total".
Code below. It goes through all the sheets and adds data to a new sheet called "Together".
However, I want him to omit two specific sheets.
I guess it'll be something like
But I don't know how to finish it
How do I do that?
Any help will be welcome
```
```
But now he has this question that I can't handle.
How omit sheets from the loop?
I want to skip copying tables from sheets named "Data" and "Total".
Code below. It goes through all the sheets and adds data to a new sheet called "Together".
However, I want him to omit two specific sheets.
I guess it'll be something like
VBA Code:
`If Not Sheets(jCt).Name = "Data" and "Total" Then`
How do I do that?
Any help will be welcome
```
VBA Code:
Sub Combination()
Dim jCt As Integer
Dim ws As Worksheets
Dim myRange As Range
Dim lastRow As Long
lastRow = 1
'Removes the "Together" sheet, if any
If sheetExists("Together") Then
Application.DisplayAlerts = False
Sheets("Together").Delete
Application.DisplayAlerts = True
MsgBox "Worksheet ""Together"" deleted!"
End If
Worksheets.Add ' Adds a sheet to the first place
Sheets(1).Name = "Together"
' Sheet processing
For jCt = 2 To Sheets.Count ' From Sheet 2 to the last
Set myRange = Sheets(jCt).Range(Sheets(jCt).Cells(1, 1), Sheets(jCt).Range("A1").SpecialCells(xlCellTypeLastCell))
Debug.Print Sheets(jCt).Name, myRange.Address
'Copying Sheets
myRange.Copy Destination:=Sheets("Together").Range("A1").Offset(lastRow - 1, 0)
lastRow = lastRow + myRange.Rows.Count + 0 ' Adds the number of rows below the last record
Next
MsgBox "The sheet ""Together"" is created"
End Sub
Function sheetExists(sheetToFind As String) As Boolean
sheetExists = False
For Each Sheet In Worksheets
If sheetToFind = Sheet.Name Then
sheetExists = True
Exit Function
End If
Next Sheet
End Function