ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro to Delete a Row (https://www.excelbanter.com/excel-programming/360863-macro-delete-row.html)

LPS

Macro to Delete a Row
 
My client is using Excel 2000 in the Windows 2000 O/S. He would like to
create a macro that checks a cell to see if it is empty. If it is empty,
nothing happens, if it is not empty, the entire row is deleted. And then the
next row is checked for the same thing.

Can anyone tell me how to do this?
Thank you,
--
LPS

[email protected]

Macro to Delete a Row
 
If you look up delete in help, you will find an example that is almost
what you need


This example sorts the data in the first column on Sheet1 and then
deletes rows that contain duplicate data.

Worksheets("Sheet1").Range("A1").Sort _
key1:=Worksheets("Sheet1").Range("A1")
Set currentCell = Worksheets("Sheet1").Range("A1")
Do While Not IsEmpty(currentCell)
Set nextCell = currentCell.Offset(1, 0)
If nextCell.Value = currentCell.Value Then
currentCell.EntireRow.Delete
End If
Set currentCell = nextCell
Loop


The only difference here is the test - this has nextcell.value being
compared to currentcell.value, you simply need to test
currentcell.value for being blank (len for example would do this)



All times are GMT +1. The time now is 12:41 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com