View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Arlen Arlen is offline
external usenet poster
 
Posts: 86
Default Cycle through all worksheets in a workbook

Mike,

Thanks for helping. I tried this code and I still get only one sheet at a
time.

I'll keep playing with it.

Arlen

"Mike H" wrote:

Hi,

Several ways, here's one

Dim x As Long
For x = 1 To Worksheets.Count
MsgBox Worksheets(x).Name
'do something
Next


Mike

"Arlen" wrote:

I have some code which automatically copies and pastes data off all workbooks
(1 sheet each) in a folder.

How about if I want to make it cycle through multiple worksheets within a
workbook before closing it?

I made a few modifications to this loop, but it is not working. Anyone know
why?

Do While sFil < ""
Workbooks.Open sPath & sFil
For Each w In ActiveWorkbook.Worksheets
<---added this
With ThisWorkbook.Worksheets("Bulk")
<---and this
k = ThisWorkbook.Sheets(1).Range("A65536").End(xlUp).R ow
n = k + 4
Set oWbk = Workbooks.Open(sPath & "\" & sFil)
Range("B4:Z1000").Copy
Set w = ThisWorkbook.Sheets(1)
ThisWorkbook.Sheets(1).Range("A" & n).PasteSpecial
End With
<---added this
Next w
<---and this
oWbk.Close True <--should this be False

I appreciate your help as always.

Arlen