ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   delete rows in a given range (https://www.excelbanter.com/excel-programming/436719-re-delete-rows-given-range.html)

Ryan H

delete rows in a given range
 
Just adjust the worksheet name, first row, and last row variables and it
should work for you. If you don't want the entire row deleted let me know.
If this helps click "YES" below.

Sub DeleteRows()

Dim wks As Worksheet
Dim lngFirstRow As Long
Dim lngLastRow As Long

Set wks = Sheets("Sheet1")
lngFirstRow = 2
lngLastRow = wks.Cells(Rows.Count, "A").End(xlUp).End

' clears empty rows from sheet
With wks
For i = lngLastRow To lngFirstRow Step -1
If Trim(.Cells(i, "A")) = "" Then
.Cells(i, "A").EntireRow.Delete Shift:=xlUp
End If
Next i
End With
End Sub
--
Cheers,
Ryan


"Wen" wrote:

Anyone has a good sub to delete from a given range any row with blank index
cell?
For example, I have a table range with column A titled "Name" as index
column. I need a sub that deletes any row where column A is blank, but say,
column C has non-blank value. it is not the same as deleting all blank rows
in a range.
TIA.
Wen

.



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

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