Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15648

How to copy many sheets in excel workbook to another sheet in another workbook?

$
0
0
Dear All

I am trying to copy a specific range from many sheets in excel workbook to another sheet in another workbook

the problem it gives the data of the last sheet only

Here is my code:

Code:

Sub CollectData()

Dim wb1 As Workbook
Dim wb2 As Workbook
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim I As Integer

Application.DisplayAlerts = False
Set wb1 = ThisWorkbook
Set wb2 = Workbooks.Open("C:\Users\moheb.mikhail\Documents\Amr\Timesheet.xlsx")
Set ws1 = wb1.Sheets("Jan")

I = 0
 For Each ws2 In wb2.Sheets
 If Len(ws2.Name) > 0 Then
  ws2.Range("A2:G50").Copy Destination:=ws1.Range("A2:G50")
  End If
  I = I + 1
  Next ws2
Application.DisplayAlerts = True
wb2.Close (savechanges = True)

End Sub

Thanks your support

Moheb Labib

Viewing all articles
Browse latest Browse all 15648

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>