I'm a beginner in VBA and I have a problem in above subject which I want to copy specific range from many sheets in workbook to one sheet in another workbook I searched the net and finally I reached to a code which runs but it gives me the last sheet data only not all sheets
I have a Workbook (WB1) - Current Workbook
I have another Work Book (WB2) - Copy from Workbook
I have WS1 in the Current Workbook
I have WS2 in the Copy from Workbook
The Work sheets names in WB2 are Numbers like 1,2 and so on
I used the following code
Sub CollectData()
Dim wb1 As Workbook
Dim wb2 As Workbook
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Application.DisplayAlerts = False
Set wb1 = ThisWorkbook
Set wb2 = Workbooks.Open("Path")
Set ws1 = wb1.Sheets("Jan")
For Each ws2 In wb2.Sheets
If Len(ws2.Name) > 0 Then
ws2.Range("A2:G50").Copy Destination:=ws1.Range("A2:G50")
End If
Next ws2
Application.DisplayAlerts = True
wb2.Close (savechanges = True)
The Code gives me data in the last sheet only ?? in this case 2
Appreciate your support.
Thanks, Regards
If Len(ws2.Name) > 0 Then
andApplication.DisplayAlerts = False
? The first one could be answered like I don't want to include worksheets that ... and the second one could be answered like I don't want a dialogue to popup when .... – VBasic2008