Loop without Do error

  • Thread starter Thread starter Steph
  • Start date Start date
S

Steph

Hello. Can anyone figure out why I am getting a Loop without Do error with
the below code? I am trying to populate a listbox with ONLY visible sheets.
Thanks!

Private Sub Worksheet_Activate()
Dim intsheets As Integer
Dim ws As Worksheet

ListBox1.MultiSelect = fmMultiSelectMulti
ListBox1.Clear

intsheets = 1

Do While intsheets < (Sheets.Count + 1)
If ws.Visible = True Then
ListBox1.AddItem Worksheets(intsheets).Name
Else
intsheets = intsheets + 1
Loop
End Sub
 
You have a block "If" statement without an "End If". Excel is taking the
"Loop" as being inside the "If" statement with no "Do" inside the same "If"
statement. You need an "End If" before the "Loop" line. HTH Otto
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top