ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   delet rows based on cel content (https://www.excelbanter.com/excel-programming/360869-delet-rows-based-cel-content.html)

Ivano

delet rows based on cel content
 
Hi,
How can I create a macro that would delete two rows. The first row is the
one where the cell value in Column A is "L" and the second row is the row
above it.
So if A15, A20, A23 has the value (and only value) of "L" then delete it and
the row above it, which would be A14, A19, A22.

Thanks,



SLAnt

delet rows based on cel content
 

Hi,
How can I create a macro that would delete two rows. The first row is
the
one where the cell value in Column A is "L" and the second row is the
row
above it.
So if A15, A20, A23 has the value (and only value) of "L" then delete
it and
the row above it, which would be A14, A19, A22.

Thanks,


Ah

I wrote something similar earlier today at work.

Sub DeleteLRows()
Dim cl As Range
For Each cl In Selection
cl.Select
If UCase(ActiveCell.Value) = "L" Then
ActiveCell.EntireRow.Delete
ActiveCell.Offset(-1, 0).EntireRow.Delete
End If
Next
End Sub

it might need a tweak but it should give you something towards what
uyou need.
it works on cells you select.



somethinglikeant


--
SLAnt
------------------------------------------------------------------------
SLAnt's Profile: http://www.excelforum.com/member.php...o&userid=34184
View this thread: http://www.excelforum.com/showthread...hreadid=539933


Crowbar via OfficeKB.com

delet rows based on cel content
 
No tested it, just wrote it, may need a slight change

For x = 5000 to 1 step -1
If sheet1.cells(x, 1).value = "L" then
rows(x).delete
rows(x -1).delete
end if
next x



--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200605/1

Ivano

delet rows based on cel content
 
Hi SLAnt,
Thanks for the code. I'm also trying to learn to program with VBA so what
is cl mean in your code?

"SLAnt" wrote:


Hi,
How can I create a macro that would delete two rows. The first row is
the
one where the cell value in Column A is "L" and the second row is the
row
above it.
So if A15, A20, A23 has the value (and only value) of "L" then delete
it and
the row above it, which would be A14, A19, A22.

Thanks,


Ah

I wrote something similar earlier today at work.

Sub DeleteLRows()
Dim cl As Range
For Each cl In Selection
cl.Select
If UCase(ActiveCell.Value) = "L" Then
ActiveCell.EntireRow.Delete
ActiveCell.Offset(-1, 0).EntireRow.Delete
End If
Next
End Sub

it might need a tweak but it should give you something towards what
uyou need.
it works on cells you select.



somethinglikeant


--
SLAnt
------------------------------------------------------------------------
SLAnt's Profile: http://www.excelforum.com/member.php...o&userid=34184
View this thread: http://www.excelforum.com/showthread...hreadid=539933



windsurferLA

delet rows based on cel content
 
C1 appears to be a variable, like "x" except the programmer chose to
call it "C1." The programmer specified that it is a special kind of
variable, that is that it is a variable that describes a Range.

Ivano wrote:
Hi SLAnt,
Thanks for the code. I'm also trying to learn to program with VBA so what
is cl mean in your code?

"SLAnt" wrote:

Hi,
How can I create a macro that would delete two rows. The first row is
the
one where the cell value in Column A is "L" and the second row is the
row
above it.
So if A15, A20, A23 has the value (and only value) of "L" then delete
it and
the row above it, which would be A14, A19, A22.

Thanks,


Ah

I wrote something similar earlier today at work.

Sub DeleteLRows()
Dim cl As Range
For Each cl In Selection
cl.Select
If UCase(ActiveCell.Value) = "L" Then
ActiveCell.EntireRow.Delete
ActiveCell.Offset(-1, 0).EntireRow.Delete
End If
Next
End Sub

it might need a tweak but it should give you something towards what
uyou need.
it works on cells you select.



somethinglikeant


--
SLAnt
------------------------------------------------------------------------
SLAnt's Profile: http://www.excelforum.com/member.php...o&userid=34184
View this thread: http://www.excelforum.com/showthread...hreadid=539933




All times are GMT +1. The time now is 03:11 AM.

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