Excel VBATutorial            

             

Excel VBA Macros

Email to excel-vba.com

Excel Tutorial on Macros

 Excel Consulting

Here is a sample of what you will find
in the downloadable 
Tutorial on Excel macros

VBA Code for tatements

Among the VBA statements that you will discover in the downloadable tutorial on Excel macros, there are the "If" statement including Then, ElseIf and End If, there is the "Do" statement  including Loop, Until, While and Exit, there is the "For" statement including To, Step, Next and Exit, there is the powerful "Select Case" statement including Case, End Select and Exit and other statements.

A lot of visitors ask us how they can delete the entire lines when a certain cell is empty. For example, in the table below rows 2 and 5 should be deleted:

Excel vba statement

First enter xxx where you want the loop to stop (below the last value: B7). Select the cell at the top of the column containing the values to be considered (B1)and run the macro.

Sub proDelete()

        Range("B1").Select
        Do Until Selection.Value = "xxx"
                  If Selection.Value = "" Then
                          Selection.EntireRow.Delete
                  Else
                          Selection.Offset(1, 0).Select
                  End If
            Loop

            Range("A1").Select

End Sub

If you have completed the free exercises "Free Basics", just copy/paste the macro above in the Visual Basic editor and run it.

Exiting a Loop

In the loop above if you want the loop to stop when it finds the value 99 you can add this line of code within the loop:
If Selection.Value = 99  Then Exit Do

Exit allows you to get out of almost anything like:
Exit Sub
Exit For
Exit Do


We hope you have enjoyed this tip
For more on this topic and a complete course on Excel macros download the
Tutorial on Excel Macros


To organize your discovery of Excel macros, the downloadable Tutorial on Excel Macros is divided in three sections (all 3  sections part of the single download):

Section 1: Excel Macros Programming (Chapters 1 to 10)
This section is about recording, writing, modifying and testing macros in the Visual Basic Editor. You will also learn about security and discover "events" (an event is what starts the macro).

Section 2: Excel VBA Vocabulary (Chapters 11 to 23)
Developing a macro is communicating with Excel and to do so you need to use a language called Visual Basic for Applications (VBA). In section 2 you will learn all the VBA vocabulary that is essential to work with business data (accounting, sales, production and others).

Section 3: Forms and Controls in VBA for Exce (Chapters 24 to 33)
The userform is a small or large dialog window that you create and allows the user to submit values that will be used by your macros. To these userforms you will add controls (command buttons, text boxes, list boxes and others) and program them.