Thread: Do Until?
View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein \(MVP - VB\)[_1387_] Rick Rothstein \(MVP - VB\)[_1387_] is offline
external usenet poster
 
Posts: 1
Default Do Until?

You could have your macro call this subroutine passing in the name of the
sheet you want to stop at...

Sub ListSheetsUpTo(SheetName As String)
Dim X As Long
For X = 1 To Worksheets.Count
If UCase$(Worksheets(X).Name) < UCase$(SheetName) Then
Cells(X, 1).Value = Worksheets(X).Name
Else
Exit Sub
End If
Next
End Sub

You would call this subroutine from your own macro like this...

ListSheetsUpTo "SheetX"

Rick


"Pam" wrote in message
...
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