PC Review


Reply
Thread Tools Rate Thread

DELETE CELL OF ZERO VALUE

 
 
K
Guest
Posts: n/a
 
      29th May 2008
Hi all, I want macro that if any cell in range L2 to last value cell
in column L have zero value then row from column H to M of that cell
should be deleted (Delete Shift:= xlUP)
Please can anybody help.
 
Reply With Quote
 
 
 
 
Norman Jones
Guest
Posts: n/a
 
      29th May 2008
Hi K,

In a standard module, try:


'================>>
Public Sub DeleteRange()
Dim WB As Workbook
Dim SH As Worksheet
Dim Rng As Range
Dim rCell As Range
Dim delRng As Range
Dim iRow As Long
Dim CalcMode As Long
Dim ViewMode As Long

Set WB = Workbooks("myBook.xls") '<<===== CHANGE
Set SH = WB.Sheets("Sheet1") '<<===== CHANGE

With SH
iRow = LastRow(SH, .Columns("L:L"))
Set Rng = SH.Range("L1:L" & iRow)
End With

On Error GoTo XIT
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

With ActiveWindow
ViewMode = .View
.View = xlNormalView
End With

SH.DisplayPageBreaks = False


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

If Not delRng Is Nothing Then
delRng.EntireRow.Delete
Else
'Do nothing
End If

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

ActiveWindow.View = ViewMode

End Sub
'--------------->

Function LastRow(SH As Worksheet, _
Optional Rng As Range)
If Rng Is Nothing Then
Set Rng = SH.Cells
End If

On Error Resume Next
LastRow = Rng.Find(What:="*", _
After:=Rng.Cells(1), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On Error GoTo 0
End Function
'<<================






---
Regards.
Norman
"K" <(E-Mail Removed)> wrote in message
news:2eed0a53-d0e2-47f3-97ca-(E-Mail Removed)...
> Hi all, I want macro that if any cell in range L2 to last value cell
> in column L have zero value then row from column H to M of that cell
> should be deleted (Delete Shift:= xlUP)
> Please can anybody help.


 
Reply With Quote
 
Mike H
Guest
Posts: n/a
 
      29th May 2008
Hi,

Right click your sheet tab, view code and paste this in and run it

Sub stance()
Dim copyrange As Range
lastrow = Cells(Cells.Rows.Count, "L").End(xlUp).Row
Set myrange = Range("H2:H" & lastrow)
For Each c In myrange
If Not IsEmpty(c.Offset(, 4)) And c.Offset(, 4).Value = 0 Then
If copyrange Is Nothing Then
Set copyrange = c.Resize(, 6)
Else
Set copyrange = Union(copyrange, c.Resize(, 6))
End If
End If
Next

If Not copyrange Is Nothing Then
copyrange.Delete Shift:=xlUp
End If
End Sub

Mike

"K" wrote:

> Hi all, I want macro that if any cell in range L2 to last value cell
> in column L have zero value then row from column H to M of that cell
> should be deleted (Delete Shift:= xlUP)
> Please can anybody help.
>

 
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:01 PM.