VBA for Excel 2007 tutorial-loop to move to end of list

VBA loop: move to end of list

In this example, We use VBA do until loop statement to move to the insertion point. The point to insert data is at the end of the list.

To run this example VBA code, you will need a Form and two Labels, two TextBox, and one CommandButton.
You may copy and paste the sample data in to your current worksheet.

BookID Title
B001 VBA Programming for Excel 2007
B002 C++ Programming for Beginners
B003 Learn Java in 60 hours
B004 C# Programming for Java Developer
B005 C++ Graphics and Game Programming

VBA for Excel: VBA code example of using VBA do until loop to locate the end of the list to insert data to the Excel sheet
VBA code for this example:

Private Sub CommandButton1_Click()
    addBook TextBox1.Text, TextBox2.Text
End Sub
Sub addBook(ID As String, Title As String)
    Dim row As Integer
    row = 1
    Do Until Cells(row, 1) = ""
        row = row + 1 'move to the end of the list
    'add data
    Cells(row, 1) = ID
    Cells(row, 2) = Title
End Sub


This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.