Excel Guides

While Wend Structure in Excel

The While Wend structure in Excel allows you to repeat a set of statements while a condition is True. The syntax for this structure is:

While condition
   [statements]  
Wend

The condition can be any expression that returns a Boolean value. If the condition is True, the statements between the While and Wend keywords are executed. Once the statements have been executed, the condition is evaluated again. If it is still True, the statements are executed again. This process repeats until the condition becomes False. If the condition is False, execution continues with the statement following the Wend.

Example 1: Using a While Wend Loop to Find an Empty Cell

This example uses a While Wend loop (shown in red) to find the first empty cell in column A. The code then enters the text "Hello" in that cell.

Sub Test()

[   ]*

< p class = MsoNormal > & nbsp ; & nbsp ; & nbsp ; & nbsp ; Dim i As Integer: p > < p class = MsoNormal > & nbsp ; & nbsp ; & nbsp ; & nbsp ; i = 1< o>: p > < p class = MsoNormal > & nbsp ; & nbsp ; & nbsp ; While Cells ( i , 1 ) . Value & lt;& gt ""< o>: p > < div align = center > < table border = " 1 " width=100% id=table2 style=border collapse : collapse >
[endif][if gte vml 1 ]>[endif]--[if gte vml 1]>

Move beyond 

Excel

Get started with Causal today.
Build models effortlessly, connect them directly to your data, and share them with interactive dashboards and beautiful visuals.