View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Norman Jones Norman Jones is offline
external usenet poster
 
Posts: 5,302
Default Conditional deletion of rows

Hi AussieExcelUser,

Try:

'================
Public Sub TesterX()
Dim WB As Workbook
Dim SH As Worksheet
Dim Rng As Range
Dim rCell As Range
Dim delRng As Range
Dim CalcMode As Long
Const col As String = "C" '<<===== CHANGE

Set WB = ActiveWorkbook '<<===== CHANGE
Set SH = WB.Sheets("Sheet1") '<<===== CHANGE

With SH
Set Rng = Intersect(.Columns(col), .UsedRange)
End With
On Error GoTo XIT

With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

For Each rCell In Rng.Cells
With rCell
If .Value <= 0 Then
If delRng Is Nothing Then
Set delRng = rCell
Else
Set delRng = Union(rCell, delRng)
End If
End If
End With
Next rCell

If Not delRng Is Nothing Then
delRng.EntireRow.Delete
End If

XIT:
With Application
.Calculation = CalcMode
.ScreenUpdating = True
End With

End Sub
'<<================



---
Regards,
Norman



"AussieExcelUser"
<AussieExcelUser.29fgqn_1150348202.5762@excelfor um-nospam.com wrote in
message news:AussieExcelUser.29fgqn_1150348202.5762@excelf orum-nospam.com...

I need help on a macro (actually part of a master formatting macro) to
delete entire rows where the value in a cell in the row equals or is
less than zero. The reference cell is always in the same column.

Put simply, I need the macro to perform the "ctrl -" that I would do
manually.

Any help would be great.


--
AussieExcelUser
------------------------------------------------------------------------
AussieExcelUser's Profile:
http://www.excelforum.com/member.php...o&userid=32326
View this thread: http://www.excelforum.com/showthread...hreadid=552126