Struggling with Blank Rows in Excel? Here's a Macro to Tidy Up Your Worksheet

prodip_bata
I don't know whether this is the right forum or not. Here, I am sharing with you how to delete blank rows in the same worksheet using a macro. Please refer to the attached file where step-by-step guidelines are available along with the clarification behind the commands. If you need to handle large data in Excel and often require arranging the data correctly, then this macro may be very useful to you.

Regards
1 Attachment(s) [Login To View]

CiteHR.AI
Guide to Deleting Blank Rows in Excel Using a Macro

To delete blank rows in the same worksheet using a macro in Excel, follow these steps:

1. Press `Alt + F11` to open the Visual Basic for Applications (VBA) editor.
2. Click on `Insert` in the menu bar and select `Module` to insert a new module.
3. Copy and paste the following VBA code into the module:

```vba
Sub DeleteBlankRows()
Dim rng As Range, cell As Range
Dim delRange As Range
Dim ws As Worksheet

Set ws = ThisWorkbook.Sheets("Sheet1") ' Change "Sheet1" to your sheet name

On Error Resume Next
Set rng = ws.UsedRange
On Error GoTo 0

If Not rng Is Nothing Then
For Each cell In rng
If Application.WorksheetFunction.CountA(cell.EntireRo w) = 0 Then
If delRange Is Nothing Then
Set delRange = cell
Else
Set delRange = Union(delRange, cell)
End If
End If
Next cell
End If

If Not delRange Is Nothing Then
delRange.EntireRow.Delete
End If
End Sub
```

4. Modify the code to specify the correct sheet name if needed (change `"Sheet1"` to your actual sheet name).
5. Press `F5` to run the macro. This will delete all blank rows in the specified worksheet.

By following these steps, you can efficiently delete blank rows in Excel using a macro, streamlining your data management process.
1 Attachment(s) [Login To View]

If you are knowledgeable about any fact, resource or experience related to this topic - please add your views. For articles and copyrighted material please only cite the original source link. Each contribution will make this page a resource useful for everyone. Join To Contribute