A While
/Wend
loop can only be exited prematurely with a GOTO
or by exiting from an outer block (Exit sub
/function
or another exitable loop)
Change to a Do
loop instead:
Do While True
count = count + 1
If count = 10 Then
Exit Do
End If
Loop
Or for looping a set number of times:
for count = 1 to 10
msgbox count
next
(Exit For
can be used above to exit prematurely)
Related Contents:
- Test or check if sheet exists
- Using a UDF in Excel to update the worksheet
- Cycle through sub-folders and files in a user-specified root directory [duplicate]
- Delete row based on partial text
- Way to run Excel macros from command line or batch file?
- Run Excel Macro from Outside Excel Using VBScript From Command Line
- Open Excel file for reading with VBA without display
- For Loop not fully cycling in excel VBA [duplicate]
- Easiest way to loop through a filtered list with VBA?
- Save multiple sheets to .pdf
- Excel VBA autofilter all but three
- Copy/Paste/Calculate Visible Cells from One Column of a Filtered Table
- Does the VBA “And” operator evaluate the second argument when the first is false?
- Are there disadvantages in putting code into Userforms instead of modules?
- Dir() function not working in Mac Excel 2011 VBA
- VBA – Write all possible combinations of 4 columns of data [duplicate]
- Populate unique values into a VBA array from Excel
- VBA Shell function in Office 2011 for Mac
- Delete a row in Excel VBA
- Split cell values into multiple rows and keep other data
- How do you run a .exe with parameters using vba’s shell()?
- Excel VBA – Range.Copy transpose paste
- Call a Sub with a String
- Obtain attribute names from XML using VBA
- How to remove all non alphanumeric characters from a string except period and space in excel?
- Delete Row based on Search Key VBA
- Is there a way to slow down a Web Scraper so it will pick up the code?
- Excel 2013 VBA Clear All Filters macro
- Unicode string literals in VBA
- Excel vba refresh wait
- ShowAllData method of Worksheet class failed
- Translate text using vba
- Get Unicode characters with charcode values greater hex `FFFF`
- Excel VBA – exit for loop
- How to add parameters to an external data query in Excel which can’t be displayed graphically?
- Rounding in MS Access
- Get Timezone Information in VBA (Excel)
- How to convert 32 bit VBA code into 64 bit VBA code
- Email a single attachment from folder of files each to a different person
- Excel VBA to match and line up rows
- How to run a string as a command in VBA
- Delete all duplicate rows Excel vba
- How to delete rows in Excel based on criteria using VBA?
- Outputting Excel rows to a series of text files
- XML parse VBA excel (function trip, & MSXML2.DOMDocument)
- How to find Number of Occurences of Slash from a strings
- Renaming Files with Excel VBA
- How to Send Email When Computer is Locked?
- Sending object array to variant works before August 2019 Windows update, but fails after update
- return csv file as recordset