VBA example - Excel 2007: VBA loop to delete blank rows

VBA loop to delete blank rows

In this example, We will use a VBA loop (for loop) to  delete the blank rows in Excel sheet. The blank rows sometimes are unnecessary and need to be removed. See the example text below:

VBA MS Excel
Excel 2007
VBA array
VBA code to delete blank row
VBA loop
Microsoft Excel 2007
VBA looping throug Excel sheet
VBA MS Access
VBA programming for Excel
VBA example code in Excel
Excel VBA example code
Rearrange information with VBA code

To run this example VBA code, you will need a Form, and a CommandButton. You may type the sample text above in to your current worksheet.

VBA MS Excel: VBA loop to locate the blank rows and delete them

VBA code for this example:

Option Explicit


Private Sub CommandButton1_Click()
    Dim i As Integer
    For i = 1 To 100 'Test for 100 rows. You can make change
        If Trim(Cells(i, 1)) = "" Then 'Detect the black row
            rows(i).Delete 'Delete it
        End If
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.