Thread: Do Until?
View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
joel joel is offline
external usenet poster
 
Posts: 9,101
Default Do Until?

I forgot the "End IF"

x = 6
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
If ws.Name < "X" Then
Cells(x, 1).Value = ws.Name
x = x + 1
Else
Exit For
End If
Next ws

"Pam" wrote:

Thanks for the quick reply; however, it isn't recognizing the "For" and gives
me a compile error.

"Joel" wrote:

x = 6
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
if ws.name < "X" then
Cells(x, 1).Value = ws.Name
x = x + 1
else
exit for
Next ws



"Pam" wrote:

I'm fairly new at this..
I want to list all worksheets in my workbook until one named x.
I'm using this code:
Sub listworksheets()
x = 6
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
Cells(x, 1).Value = ws.Name
x = x + 1
Next ws

How do I change code to do what I want.

Thank you
End Sub