Instruction How To Use The While Loop In Excel Vba Macro -Simple Steps


 icon excel in cartoons

As you learn about the different possible functions through the macro that are available in Excel will be able to create procedures through the loop while statement in VBA. VBA is a program that allows you to create macros in Excel.

Creating macros with VBA you can make Excel tasks more quickly and easily. copy and paste cells in Excel , crear graphics or cell count data.

These are conditions useful for tables that require a set of parameters that will determine a specific outcome.

How to Use Instruction while loop in Excel VBA Macro -Simple Steps

You may also be interested in:

The modules are created in the section macros allow the user to meet developer procedures considered impossible.

Thus, if using accesses the toolbar will allow not perform a function, the encoding embodied in the Editor visual Basic be able to create within Excel parameters so you get the desired result.

What is the loop while statement in VBA and how does it work?

Creating encodings containing the instruction of the English term While or Wend are embodied to achieve repeat a specific type of procedure.

The macro code consists of add-ons that will form such parameters than previously discussed, among which are set as follows:

  • Mainly, the condition is a required information determined through a string or number value which determines whether the content is true or false.
  • Because if the information entered and requested by the person meets the conditions set in the code, this is true and the loop is performed.
  • On the other hand, instruction is an optional parameter considered , but it really is who assigns meaning to the probability of outcome.

 green Excel icon

Based on the series of procedures to be performed again and again until the user establishes a false condition.

Operation Method

Whatever structure established in the code , the loop has the ability to be repeated while the condition being fulfilled.

When it starts executing the function or procedure, it begins to be analyzed top-down .

In this way, the loop is studying the condition placed on the top line and if the rest of the information is within the parameters is taken as true and bottom lines running to « While «.

Once the program returns come to the term « Loop » to the beginning and re-analyze the condition has been entered repeatedly.

When a change occurs in the information table that achieves the condition turn into false to stop the repetition of the loop indefinitely.

This is how While stops running and the flow of the program established by the code passes make judgments found under» Loop «.

Sample Code using the while loop

The instruction of the While Loop in VBA is set as follows in the example of a list of hospital rooms to determine if it is available to assign it to a patient in need.

 several Excel icons green

Under habestatus ()

Row = 2

Do While Cells (row 1) & lt; & gt; «»

If (Cells (row, 2) & lt; 500 And Cells (row, 3) = «Dirty») Then

Cells (row 4) = «Not available in 4th floor»

End If

If (Cells (row, 2) & lt; 500 And Cells (row, 3) = » clean») Then

Cells (row 4) = «‘Disponible on 4th floor»

End If

If (Cells (row, 2) & lt; 400 And Cells (row, 3) = «Dirty») Then

Cells (row 4) = «Unavailable on 3rd floor»

End If

If (Cells (row, 2) & lt; 400 And Cells (row, 3) = » clean») Then

Cells (row 4) = «Available in 3rd floor»

End If

If (Cells (row, 2) & lt; 300 And Cells (row, 3) = «Dirty») Then

Cells (row 4) = «Not available on 2nd floor»

End If

If (Cells (row, 2) & lt; 300 And Cells (row, 3) = » clean») Then

Cells (row 4) = «Available in 2nd floor»

End If

If (Cells (row, 2) & lt; 200 And Cells (row, 3) = «Dirty») Then

Cells (row 4) = «Not available in 1st floor»

End If

If (Cells (row, 2) & lt; 200 And Cells (row, 3) = » clean») Then

Cells (row 4) = «Available in 1st floor»

End If

Row = row + 1

Loop

End Sub

How useful did you find this content?

Click on a star to rate!

Average score 0 / 5. Counting of votes: 0

So far, no votes. Be the first to rate this content.

I'm sorry this content was not useful for you!

Let me improve this content!

Tell me, how can I improve this content?

You may also be interested in:

Deja un comentario