Question : Modify Syntax

I have 5 different worksheets
I currently have 5 worksheets named:  Apple, Orange, Banana, Grape, Lemon

How can I modify the following to first add a new worksheet to the worbook and have it named FRUIT, and then run the below snytax on the first five worksheets (Apple, Orange, Banana, Grape & Lemon)

Sub test()
  Dim wksPasteTo As Worksheet
  Dim rngPasteTo As Range
  Range("A1:I400").Select
  Selection.Copy
  Set wksPasteTo = ActiveWorkbook.Sheets("FRUIT")
  Set rngPasteTo = wksPasteTo.Range("a3")
  Do Until rngPasteTo = ""
     Set rngPasteTo = rngPasteTo.Offset(1)
  Loop
  wksPasteTo.Paste rngPasteTo
End Sub

Answer : Modify Syntax

oops, need to add sht to this line:
Range("A1:I400").Copy

Changed to:
sht.Range("A1:I400").Copy

Amended code below.

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
Sub test()

    Dim wksPasteTo As Worksheet
    Dim rngPasteTo As Range
    Dim sht As Worksheet
    
    Worksheets.Add , Sheets(Worksheets.Count)
    ActiveSheet.Name = "FRUIT"
    
    Set wksPasteTo = ActiveWorkbook.Sheets("FRUIT")
    Set rngPasteTo = wksPasteTo.Range("a3")
    
    For Each sht In ThisWorkbook.Worksheets
        If sht.Name <> "FRUIT" Then
            sht.Range("A1:I400").Copy
            Do Until rngPasteTo = ""
                Set rngPasteTo = rngPasteTo.Offset(1)
            Loop
            wksPasteTo.Paste rngPasteTo
        Else
        End If
    Next sht
    
End Sub
Random Solutions  
 
programming4us programming4us