Excel Do

  



Using the Excel app, just take a picture of a printed data table on your Android or iPhone device and automatically convert the picture into a fully editable table in Excel. This new image recognition functionality eliminates the need to manually enter hard copy data. Copy the example data in the following table, and paste it in cell A1 of a new Excel worksheet. For formulas to show results, select them, press F2, and then press Enter. If you need to, you can adjust the column widths to see all the data.

Opening a spreadsheet When you first open Excel (by double-clicking the icon or selecting it from the Start menu), the application will ask what you want to do. Using the Excel app, just take a picture of a printed data table on your Android or iPhone device and automatically convert the picture into a fully editable table in Excel. This new image recognition functionality eliminates the need to manually enter hard copy data.

The VBA programming language supports the Do While Loop. In this article, we will learn how to use the Do While Loop in Excel VBA.

The Syntax of Do While Loop

The VBA Do While Loop has two syntaxes:

Entry Control Do While Loop

In this syntax, the condition is first checked. If the condition is matched, the control enters the loop, else loop is terminated.
Exit Control Do While Loop

In this syntax, control enters the loop first. After executing each task, VBA checks the condition in the end. If the condition is True, the Do While Loop continues, else the loop terminates immediately. Use this syntax, when you want your loop to be executed at least once.

Example: Delete Sheets Until Only 2 Sheets are Left

In this example we will try to delete each sheet one by one until only 2 sheets are left in the workbook using VBA Do While Loop:

The above subroutine will first check if the workbook has more than 2 sheets. If the workbook has more than 2 sheets, the control will enter the loop and will delete the current activesheet. The loop will continue until only 2 sheets are left.

If the workbook already has only 2 or 1 sheets, the control will not enter the loop and nothing will happen.

Now if you wanted to delete at least 1 sheet at starting of the loop, even if the workbook only has 2 sheets, then use the exit control do while loop.

The above subroutine will first delete 1 sheet and then it will check how many sheets are there. If they are greater than 2 sheets then the loop will continue. If the workbook is left with 2 sheets or less then the loop will exit.

The major takeaway here is that this loop will execute once at least. You can use this to repeat some tasks by asking the user. For example, you can ask a user for the password. And loop him until he enters the correct password or exits. In this scenario, you have to ask the user for the password at least once.

Note: I have used DisplayAlert property of Application object to disable the alerts. You can read about it here.

So yeah guys, this was the Do While Loop in Excel VBA. I hope it was explanatory enough. If you have any doubts regarding this or any other Excel 365/2019/2016 related query. Ask in the comments section below.

Excel

Excel Download Free Version

Related Articles:

7 Examples of For Loops in Microsoft Excel VBA | The for loop is the most used looping technique in any programming language. In VBA the For loop can be used in several ways.

The If ElseIf Statement in VBA | The If ElseIf is a basic condition checking technique for returning conditional outputs.

Delete sheets without confirmation prompts using VBA in Microsoft Excel: While deleting sheets you get an confirmation prompt. To disable it we use the Application...

Display A Message On The Excel VBA Status Bar | To display message on the status bar we use the StatusBar property of the Application object.

Excel donation list template

Popular Articles:

50 Excel Shortcuts to Increase Your Productivity | Get faster at your task. These 50 shortcuts will make you work even faster on Excel.

The VLOOKUP Function in Excel | This is one of the most used and popular functions of excel that is used to lookup value from different ranges and sheets.

COUNTIF in Excel 2016 | Count values with conditions using this amazing function. You don't need to filter your data to count specific values. Countif function is essential to prepare your dashboard.

How to Use SUMIF Function in Excel | This is another dashboard essential function. This helps you sum up values on specific conditions.

This formula uses the WEEKDAY function to test dates for either a Saturday or Sunday. When given a date, WEEKDAY returns a number 1-7, for each day of the week. In it's standard configuration, Saturday = 7 and Sunday...
Excel Do
The goal of this example is to verify input before calculating a result. The key point to understand is that any valid formula can be substituted. The SUM function is used only as an example. The logic can also be...
Conditional formatting is evaluated relative to every cell it is applied to, starting with the active cell in the selection, cell B3 in this case.To highlight matching rows, we use this logical expression:$B4=$K$5...
In the example shown, we want to mark or 'flag' records where the color is red OR green. In other words, we want to check the color in column B, and then leave a marker (x) if we find the word 'red' or 'green'. In D6,...
Note: this is a great example of a formula that is hard to understand because the cell references are hard to interpret. The gist of the logic used is this: if the time in row 4 is between the start and end times, the...
This formula relies on a technique called 'nested IFs' to handle a series of options and results. With nested IFs, one IF function is nested inside another, a process that is explained in some detail here.The formula...
This formula uses 4 named ranges, defined as follows:width=K6height=K7widths=B6:B11heights=C5:H5Conditional formatting is evaluated relative to every cell it is applied to, starting with the active cell in the...
When conditional formatting is applied with a formula, the formula is evaluated relative to the active cell in the selection at the time the rule is created. In this case, the active cell when the rule is created is...

Microsoft Excel Free Download

In the example shown, we simply want to 'mark' or 'flag' rows where the color is 'red' AND size is either 'small' or 'medium'. To return TRUE when items are red and small, we can use a logical statement constructed with...

Excel Does Not Equal

The behavior of the IF function can be easily extended by adding logical functions like AND, and OR, to the logical test. If you want to reverse existing logic, you can use the NOT function.In the example shown, we...

Excel Does Not Equal

In the example shown, we want to 'mark' or 'flag' records where the color is either red OR green AND the quantity is greater than 10. The core of the formula is the logical test inside the IF function, which looks like...