Delete Rows in Different Sheets through VBA

If you want a way to delete all the similar rows numbers in a go then this article is for you.

In this article we will learn how we can get rid of same row in multiple worksheets through macros.

 

Question): I want to delete the same row in multiple worksheets using VBA code. What I want is code to delete all the rows in the workbook regardless of how many sheets are present in the current file; I want to delete the selected row number from all the 5 sheets.

 

First of all let’s enter the similar data in all the worksheets in same location

image 1

 

We need to follow the below steps:

  • Click on Developer tab
  • From Code group select Visual Basic

 

image 2

Enter the following code in the standard module:-

Sub DeleteRows()

Dim shtArr, i As Long, xx As Long

shtArr = Array("Sheet1", "Sheet2", "Sheet3", "Sheet4", "Sheet5")

xx = Selection.Row

For i = LBound(shtArr) To UBound(shtArr)

    Sheets(shtArr(i)).Rows(xx).EntireRow.Delete

Next i

End Sub

 

 

image 3

 

  • Now place the cursor on any cell A1 & on Sheet1.
  • Press ALT + F8 to run the macro; you will find selected row number gets deleted in all the sheets.
  • Following snapshot shows sheet 1 & sheet 2 data as an example; when you run this exercise you will find similar solution in all the respective sheets.

image 4

 

 

  • If we place the cursor on any cell A2 & on Sheet2 then also the result would be similar.

 

In this case we can delete similar row number using VBA code.

 

Excel Download- Sample file- xlsm

Leave a Reply

Your email address will not be published. Required fields are marked *

Terms and Conditions of use

The applications/code on this site are distributed as is and without warranties or liability. In no event shall the owner of the copyrights, or the authors of the applications/code be liable for any loss of profit, any problems or any damage resulting from the use or evaluation of the applications/code.