View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
L. Howard L. Howard is offline
external usenet poster
 
Posts: 852
Default For Each sheet in WkBook problem

Sheets in workbook are A, B, C, D, E, F, G plus the two that are excluded in the code.

Total combined rows with data for all A to G sheets is about 52. (about 7 per sheet.)

If I run SheetsCopy1 I get about 5000 rows copied to Summary sheet, multiple repeats of correct data.

If I run SheetsCopy2 I see each sheet range to copy is properly selected and the Msgbox shows the correct sheet name.

The DeBug.Print lists the proper sheets A to G.

Code is in a standard module, and the downloaded example workbook looks to be German, saved as ...xlsm.

What little tid-bit am I overlooking here?

Thanks,
Howard

Sub SheetsCopy1()
Dim ws As Worksheet
Dim Rng As Range

For Each ws In ThisWorkbook.Sheets

If (ws.Name < "Summary") And (ws.Name < "Begin blad") Then

With ws

ws.Activate
Set Rng = Range("A2", Range("D2").End(xlDown))
Rng.Copy Sheets("Summary").Range("A" & Rows.Count).End(xlUp)(2)

End With

End If

Next
End Sub

Sub SheetsCopy2()
Dim ws As Worksheet
Dim Rng As Range
Dim lRow As Long

For Each ws In ThisWorkbook.Sheets

If (ws.Name < "Summary") And (ws.Name < "Begin blad") Then
'Debug.Print ws.Name
With ws
ws.Activate
Set Rng = Range("A2", Range("D2").End(xlDown))
Rng.Select
MsgBox ws.Name
End With

End If

Next
End Sub