ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Deleting rows preceding (https://www.excelbanter.com/excel-programming/315073-deleting-rows-preceding.html)

Robert

Deleting rows preceding
 
HI,
I have the following program that deletes the entire row when it finds the
characters "Inst" in Column A. Besides deleting just that row, I would also
like to be able to delete the three rows above it. Would I be able to change
this program and do it?
Thanks for your help.

_________________
Public Sub DeleteRows()

Dim RowNdx As Long
Dim LastRow As Long
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
For RowNdx = LastRow To 1 Step -1
If Cells(RowNdx, "A").Value = "Inst" Then
Rows(RowNdx).Delete
End If
Next RowNdx

End Sub
_________________


Frank Kabel

Deleting rows preceding
 
Hi
not tested but try:
Public Sub DeleteRows()

Dim RowNdx As Long
Dim LastRow As Long
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
For RowNdx = LastRow-4 To 1 Step -1
If Cells(RowNdx+4, "A").Value = "Inst" Then
cells(rowndx,1).resize(4,1).entirerow.Delete
End If
Next RowNdx

End Sub

"Robert" wrote:

HI,
I have the following program that deletes the entire row when it finds the
characters "Inst" in Column A. Besides deleting just that row, I would also
like to be able to delete the three rows above it. Would I be able to change
this program and do it?
Thanks for your help.

_________________
Public Sub DeleteRows()

Dim RowNdx As Long
Dim LastRow As Long
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
For RowNdx = LastRow To 1 Step -1
If Cells(RowNdx, "A").Value = "Inst" Then
Rows(RowNdx).Delete
End If
Next RowNdx

End Sub
_________________


Robert

Deleting rows preceding
 
Hi Frank,
It doesnt do anything.
I dont necessarily have to use this same program. If you have another
program that might work, would you please share it.
Thanks for your prompt reply.

Robert

"Frank Kabel" wrote:

Hi
not tested but try:
Public Sub DeleteRows()

Dim RowNdx As Long
Dim LastRow As Long
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
For RowNdx = LastRow-4 To 1 Step -1
If Cells(RowNdx+4, "A").Value = "Inst" Then
cells(rowndx,1).resize(4,1).entirerow.Delete
End If
Next RowNdx

End Sub




All times are GMT +1. The time now is 01:32 PM.

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