![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
New Member
Join Date: Apr 2002
Location: Rick
Posts: 1
|
Hi. Mr. Excel:
I have a small problem. I need a macro to automatically delete a row is a cell in a particular column has the word "DELETE" in it. For example Col. A Col. B Col. C Col. D Row 1 Hi Me You Not Row 2 Rick Excel Bob DELETE Row 3 Excel Rick Kim Nothing Row 4 Day Week Month DELETE I would like a macro to be able to automatically delete the rows that have the word "DELETE" in column D. Any help would be appreciated. Thank you. Rick |
|
|
|
|
|
#2 |
|
Board Regular
Join Date: Mar 2002
Location: =ActiveCell.Address
Posts: 478
|
Hi Rick,
I think this should do the trick. Let me know of any probs... Sub deletestuff() Dim Lastrow As Long Dim Currentrow As Long 'First, find last cell in column with data Lastrow = Range("D65536").End(xlUp).Row 'Define start point Currentrow = 1 Range("D" & Currentrow).Select Do Until Currentrow = Lastrow + 1 If ActiveCell.Value = "DELETE" Then Rows(Currentrow & ":" & Currentrow).Select Selection.Delete Shift:=xlUp Lastrow = Lastrow - 1 Else ActiveCell.Offset(1, 0).Select End If Currentrow = ActiveCell.Row Range("D" & Currentrow).Select Loop End Sub |
|
|
|
|
|
#3 |
|
Board Regular
Join Date: Feb 2002
Location: Los Angeles, CA
Posts: 752
|
Thanks AJ, I just changed some minor things and it worked fine. It except that it was case sensative, but other than that it was fine.
Parra |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|