Our goal is to find that blank row and delete it from the data.įollow below steps to delete row in excel using VBA.
One of the employees was on leave and couldn’t do sales for three months so the cells are empty for him. Now we have data for employees and their sales are done in three months Jan, Feb, and March. Note: I will Insert back the data in the excel sample sheet for demonstration.
How to clear a worksheet from vba in excel 2016 code#
Once we run the code we see the following result, The entire data has been deleted means the first five rows have been deleted as we had data in the first five rows. Step 4: Run this code by hitting F5 or Run button and see the output. Step 3: Write the following code shown below to delete the entire five rows. Step 2: In the code declare a sub-function to start writing the code, Step 1: In the developer’s tab click on Visual Basic to open VBA Editor. Follow below steps to delete row in excel using VBA. I want to delete all the first five rows. For demonstration purpose, I have the following data as shown below, But what about if we have to delete multiple rows. VBA Delete Row – Example #2Įarlier in the first example, I have deleted only a single row. Once we run the code we can see that the values from both cell A1 and B1 are removed as the entire first row has been deleted. Step 4: Run this code by hitting F5 or Run button and see the output. Step 3: Now write the following code to delete the row. Step 2: In the code segment declare a sub-function to start writing the code. Step 1: Go to the developer’s Tab click on Visual Basic to open VBA Editor. Note: To use Excel VBA we must have developer tab enabled from Files tab in the options section.įollow the below steps to delete row in excel using VBA.