Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 129
Default How to I Delete a Row if a Cell does not have a particular value?

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default How to I Delete a Row if a Cell does not have a particular value?

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" wrote in message
...
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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


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 Excel Discussion (Misc queries) 4 May 2nd 23 03:43 AM
Delete Rows if any cell in Column H is blank but do not Delete Fir manfareed Excel Programming 4 September 28th 07 05:20 PM
How to delete cell values withour deleting cell formulae perfection Excel Discussion (Misc queries) 5 June 18th 07 09:05 PM
How to delete cell values without affecting cell formulae perfection Excel Discussion (Misc queries) 0 June 18th 07 06:55 AM
Delete cell contents with input to adjacent cell Ashley Frank Excel Discussion (Misc queries) 1 October 5th 05 04:28 PM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"