LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default For Each Next Loop behaving in unexpected manner

Greetings:

I wrote the below macro which uses the For Each Next Loop. The purpose of
the macro is to select a specific cell on each worksheet except the last
worksheet in the workbook. I am surprised that in order for it to work, my
macro has to select the first sheet in the selection before entering the For
Each Next Loop and then use the ActiveSheet.Next.Select instruction in the
For Each Next Loop to move on to the next sheet to be processed. LstRowData
was computed elsewhere and is the last row of the worksheet which contains
the input data.

Sub CheckForEachNext()
'
' Hotkey: Ctrl+Shift+J
'
Dim LstRowData As Long
'Without the below instruction and the ActiveSheet.Next.Select instruction,
only the
' activesheet is processed. With the below instruction, but still without
ActiveSheet.Next.Select, only the first worksheet is processed.

ActiveWorkbook.Worksheets(1).Select
Dim WS As Worksheet
For Each WS In ActiveWorkbook.Worksheets
If ActiveSheet.Name < "Sheet1" Then
LstRowData = Range("O2")
Cells(LstRowData + 9, "W").Select

' With the below ActiveSheet.Next.Select instruction but without the above
' ActiveWorkbook.Worksheets(1).Select instruction, only the ActiveSheet
through
' the last sheet are processed.

ActiveSheet.Next.Select
Else
Exit For
End If
Next WS
MsgBox "I am done"
End Sub

--
All suggestions will be greatly appreciated. May you have a most blessed day!

Sincerely,

Michael Fitzpatrick
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Data from SQL to Excel in a formated manner.. chintu4uin Excel Programming 0 February 16th 08 08:52 AM
comapre two list of data & arranging in a same manner Sachin New Users to Excel 1 November 25th 06 01:28 PM
How do I add up row sums in a systematic manner? wicked_rich Excel Programming 1 August 15th 05 03:54 PM
shell to behave in synchronous manner rraajjiibb Excel Programming 1 May 28th 04 08:52 PM
macro needed for sorting txt in a ceratian manner Martyn Excel Programming 1 January 24th 04 02:13 PM


All times are GMT +1. The time now is 11:03 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"