Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Conditional deletion of rows


I need help on a macro (actually part of a master formatting macro) t
delete entire rows where the value in a cell in the row equals or i
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 d
manually.

Any help would be great

--
AussieExcelUse
-----------------------------------------------------------------------
AussieExcelUser's Profile: http://www.excelforum.com/member.php...fo&userid=3232
View this thread: http://www.excelforum.com/showthread.php?threadid=55212

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Conditional deletion of rows

Hi AussieExcelUser

You can try this:


Sub DeleteRows()
Dim BeginRow As Integer
Dim EndRow As Integer
Dim LoopRow As Integer
Dim chkCol As Integer

BeginRow = 1
EndRow = ActiveSheet.UsedRange.Rows.Count ' To check all lines
chkCol = 6 ' The column with the values to check

For LoopRow = BeginRow To EndRow
If Not IsEmpty(Cells(LoopRow, chkCol)) Then
If Cells(LoopRow, chkCol).Value < 0 Then
Cells(LoopRow, chkCol).EntireRow.Delete = True
End If
End If
Next LoopRow
End Sub


HTH,

RadarEye.

AussieExcelUser wrote:
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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 360
Default Conditional deletion of rows

see -

http://www.ozgrid.com/VBA/VBACode.htm

  #4   Report Post  
Posted to microsoft.public.excel.programming
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



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Conditional deletion of rows


My thanks to all who responded, I now have my macro working prefectl
and have cut some more hours of reporting effort for my clients.

Cheers

--
AussieExcelUse
-----------------------------------------------------------------------
AussieExcelUser's Profile: http://www.excelforum.com/member.php...fo&userid=3232
View this thread: http://www.excelforum.com/showthread.php?threadid=55212

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
Conditional deletion of cell contents Colin Hayes Excel Worksheet Functions 2 August 9th 07 10:31 PM
Automatic Deletion of Rows ai18ma New Users to Excel 6 April 5th 06 08:25 AM
Conditional Row Deletion Kirk P. Excel Programming 4 November 3rd 05 07:58 PM
On deletion of rows Stephen Howe Excel Discussion (Misc queries) 2 October 7th 05 06:02 PM
Problem with Conditional format deletion [email protected] Excel Discussion (Misc queries) 3 December 13th 04 05:10 PM


All times are GMT +1. The time now is 10:46 AM.

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"