![]() |
Loop without Do error
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 |
Loop without Do error
missing
End If -- Tim Williams Palo Alto, CA "Steph" wrote in message ... 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 |
Loop without Do error
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 "Steph" wrote in message ... 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 |
All times are GMT +1. The time now is 11:52 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com