PC Review


Reply
Thread Tools Rate Thread

How to I Delete a Row if a Cell does not have a particular value?

 
 
Will
Guest
Posts: n/a
 
      2nd Jun 2008
My Goal:
Run a Macro that will scan a worksheet and if the word "Accounting" is not
in the "M" column of a Row then delete that Row.

Here is what I have now. It scans the Worksheet but does not delete the rows:

Sub Make_one_sheet_per_dept()
'
' Make_one_sheet_per_dept Macro
' Macro recorded 6/2/2008 Totals each department onto it's own worksheet.
'
'
Sheets("Accounting").Select
Dim rngTotal As String
For i = 5000 To 1 Step -1
rngTotal = Range("M" & i).Select
rngTotal = Range("M" & i).Value
'rngTotal = Trim(rngTotal)
If rngTotal = "<>Accounting" Then
Rows(ActiveCell.Row).Select
Selection.Delete shift:=x1Up
End If
Next i
End Sub

Thanks Will
 
Reply With Quote
 
 
 
 
Bob Phillips
Guest
Posts: n/a
 
      2nd Jun 2008
Sub Make_one_sheet_per_dept()
Dim rngTotal As String

With Sheets("Accounting")

For i = 5000 To 1 Step -1

If .Range("M" & i).Value <> "Accounting" Then

.Rows(i).Delete
End If
Next i
End With
End Sub



--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Will" <(E-Mail Removed)> wrote in message
news:A51EF3C4-B4F1-4F50-89AD-(E-Mail Removed)...
> My Goal:
> Run a Macro that will scan a worksheet and if the word "Accounting" is not
> in the "M" column of a Row then delete that Row.
>
> Here is what I have now. It scans the Worksheet but does not delete the
> rows:
>
> Sub Make_one_sheet_per_dept()
> '
> ' Make_one_sheet_per_dept Macro
> ' Macro recorded 6/2/2008 Totals each department onto it's own worksheet.
> '
> '
> Sheets("Accounting").Select
> Dim rngTotal As String
> For i = 5000 To 1 Step -1
> rngTotal = Range("M" & i).Select
> rngTotal = Range("M" & i).Value
> 'rngTotal = Trim(rngTotal)
> If rngTotal = "<>Accounting" Then
> Rows(ActiveCell.Row).Select
> Selection.Delete shift:=x1Up
> End If
> Next i
> End Sub
>
> Thanks Will



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Weird: inside of a cell I have a small box or cell I can't delete. ACECOWBOY Microsoft Excel Misc 3 20th Oct 2009 01:41 PM
How do you delete a cell without going Table>Select>Cell then Table>Delete>Cell - phew! JethroUK© Microsoft Frontpage 3 8th Jun 2009 10:58 PM
Delete Rows if any cell in Column H is blank but do not Delete Fir =?Utf-8?B?bWFuZmFyZWVk?= Microsoft Excel Programming 4 28th Sep 2007 05:20 PM
How to delete cell values withour deleting cell formulae perfection Microsoft Excel Misc 5 18th Jun 2007 09:05 PM
Delete cell contents with input to adjacent cell Ashley Frank Microsoft Excel Misc 1 5th Oct 2005 04:28 PM


Features
 

Advertising
 

Newsgroups
 


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