How to Use Do While Loop in Excel VBA? Last Updated : 09 Sep, 2025 Comments Improve Suggest changes Like Article Like Report A Do....While loop in Excel VBA is used to repeat a set of statements as long as a given condition is true. This condition can be checked either at the start or at the end of the loop, depending on how you want the loop to behave.Flowchart:Uses of Do-While loop:The Do While loop is used in two ways:Do…while loop which checks the condition at the STARTING of the loop.Do…while loop which checks the condition at the END of the loop.Syntax 1:Do While condition [statements] [Exit Do] [statements]Loop Syntax 2: Do While [statements][Exit Do][statements]Loop conditionHow to Implement a Do While loop:Follow the below steps to implement a Do-While loop:Step 1: Define a MacroPrivate Sub Demo_Loop()End SubStep 2: Define variablesj=2i=1Step 3: Write Do While Loop. You can write condition at the beginning or at the endDo While i < 5Step 4: Write statements to be executed in loopmsgbox "Table of 2 is : " & (j*i) i=i+1Step 5: End loop.Now let's take a look at some of the examples.Example 1: Do…while loop which checks the condition at the STARTING of the loop. The below example uses Do…while loop to check the condition at the starting of the loop. The statements inside the loop are executed, only if the condition is True. We will print Table of 2 using Do...while loop;Private Sub Demo_Loop() j=2 i=1 Do While i < 5 msgbox "Table of 2 is : " & (j*i) i=i+1 LoopEnd SubOutput:Example 2: Do…while loop which checks the condition at the END of the loop. The below example checks the condition at the end of the loop. The major difference between these two syntax is explained in the following example.Private Sub Demo_Loop() i = 10 Do i = i + 1 MsgBox "The value of i is : " & i Loop While i < 3 'Condition is false.Hence loop is executed once.End SubWhen the above code is executed, it prints the following output in a message box.Output:ConclusionThe Do While loop in Excel VBA is a powerful tool for repeating tasks until a condition fails. Whether you check the condition at the beginning or the end depends on whether you want to guarantee at least one execution of your code block. Mastering these loops will help you write cleaner, more efficient VBA code. Comment More infoAdvertise with us A akshitsaxenaa09 Follow Improve Article Tags : Excel Excel-VBA ExcelGuide Explore MS Excel Tutorial - Learn Excel Online Free 11 min read Excel FundamentalIntroduction to MS Excel 5 min read Download and Install MS Excel 2024/365 Edition 4 min read Excel Spreadsheet 4 min read Workbooks in Microsoft Excel 4 min read Worksheets in Excel 4 min read Workbooks in Microsoft Excel 4 min read Delete All Rows Below Certain Row or Active Cell in Excel 5 min read Remove Hyperlinks in Excel 6 min read How to Use Fractions in Excel 6 min read Excel FormattingData Formatting in Excel 5 min read Expand Cells to Fit the Text Automatically in Excel 3 min read Excel Date and Time Formats 3 min read Insert a Picture in a Cell in MS Excel 3 min read How to Unhide and Show Hidden Columns in Excel: Step by Step Guide 9 min read Conditional Formatting in Excel 8 min read Apply Conditional Formatting Based On VLookup in Excel 3 min read How to Compare Two Columns and Delete Duplicates in Excel 3 min read How to Find Duplicate Values in Excel Using VLOOKUP 3 min read Excel Formula & FunctionBasic Excel Formulas 3 min read Use of Concatenate in Excel 5 min read Percentage in Excel 8 min read Excel LEFT, RIGHT, MID, LEN, and FIND Functions 5 min read Excel IF Function 10 min read Excel VLOOKUP Function 12 min read Dynamic Array Formulas in Excel 2 min read COUNTIF Function in Excel - Step by Step Tutorial 7 min read How To Use MATCH Function in Excel (With Examples) 6 min read Excel Data Analysis & VisualizationHow to Sort by the Last Name in Excel? 5 min read How to Sort Data by Color in Excel? 3 min read How to Swap Columns in Excel: 3 Methods Explained 8 min read Sparklines in Excel 8 min read Pivot Tables in Excel 3 min read How to Sort a Pivot Table in Excel : A Complete Guide 7 min read Pivot Table Slicers in Excel 5 min read Data Visualizations in Power View 3 min read Chart Visualizations in Excel Power View 8 min read Table Visualization in Excel Power View 5 min read Multiple Visualizations in Excel Power View 4 min read Dynamic Excel Dashboards Using Picklists 3 min read Advanced ExcelHow to Use Solver in Excel 3 min read Power Query â Source Reference as File Path in Cell 2 min read How to Create Relational Tables in Excel? 4 min read How to Import, Edit, Load and Consolidate Data in Excel Power Query? 7 min read Connecting Excel to SQLite 4 min read Handling Integers in Advanced Excel 2 min read Power Pivot for Excel 10 min read Excel Power Pivot - Managing Data Model 6 min read Table and Chart Combinations in Excel Power Pivot 3 min read Excel Data VisualizationAdvanced Excel - Chart Design 4 min read How to Create a Graph in Excel: A Step-by-Step Guide for Beginners 8 min read Formatting Charts in Excel 3 min read Create a Waterfall Chart in Excel 5 min read Scatter and Bubble Chart Visualization in Excel 5 min read Create a Pie Chart in Excel 5 min read How To Create A Pictograph In Excel? 3 min read How to make a 3 Axis Graph using Excel? 7 min read How To Create a Tornado Chart In Excel? 2 min read How to Create Flowchart in Excel: Step-by-Step Guide 6 min read Excel VBA & MacrosHow to Insert and Run VBA Code in Excel? 2 min read Variables and Data Types in VBA Excel 9 min read How to Use the VBA Editor in Excel: Quick Guide 2024 7 min read VBA Strings in Excel 8 min read VBA Find Function in Excel 5 min read ActiveX Control in Excel VBA 3 min read Multidimensional Arrays in Excel VBA 2 min read VBA Error Handling 10 min read How to Remove Duplicates From Array Using VBA in Excel? 2 min read Macros In Excel With Examples 10 min read Assigning Excel Macro to Objects 3 min read How to Enable Macros in Excel (2025): Step-by-Step Guide 9 min read Power BI & Advance Features in ExcelPower BI - Tools and Functionalities 5 min read Power BI - Data Sources and its type 4 min read Power BI - Data Sources and its type 4 min read Power BI - How to Create a Report using Excel Data in Workspace 4 min read Data Analysis Expressions (DAX) 7 min read Power BI - How to upload Excel Files to Dashboard? 3 min read Like