Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default Conditions in a macro

Hey there,

I am trying to have my marco delete all rows with a value equal to or less
then 0 (in a particular field). Any help would be great.

Thanks,
--
Damon
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Conditions in a macro

Sort them first (programmatically if you wish - do a macro record to
see how), then do a find for zero, then delete all rows below.
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 79
Default Conditions in a macro

Hi Damon.
Try:

Sub Cancellariga()
Dim R As Long
Dim LR As Long
With ActiveSheet
LR = .Cells(Rows.Count, 1).End(xlUp).Row
For R = LR To 1 Step -1
If .Cells(R, 1).Value = 0 Then
.Cells(R, 1).EntireRow.Delete
End If
Next
End With
End Sub

Regards
Eliano


On 4 Giu, 00:59, Damon wrote:
Hey there,

I am trying to have my marco delete all rows with a value equal to or less
then 0 (in a particular field). *Any help would be great.

Thanks,
--
Damon


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default Conditions in a macro

Sub DeleteRows()
Dim iLastRow As Long
Dim I As Long
iLastRow = Cells(Rows.Count, "C").End(xlUp).Row
For I = iLastRow To 1 Step -1
If Cells(I, "C").Value <= 0 Then
Rows(I).Delete
End If
Next I
End Sub

Edit the "C" to suit.


Gord Dibben MS Excel MVP

On Tue, 3 Jun 2008 15:59:02 -0700, Damon
wrote:

Hey there,

I am trying to have my marco delete all rows with a value equal to or less
then 0 (in a particular field). Any help would be great.

Thanks,


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 79
Default Conditions in a macro

Sorry Damon, ut i forget the minus sign.

If .Cells(R, 1).Value = 0 Then

is intended as:

If .Cells(R, 1).Value <= 0 Then

Eliano


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default Conditions in a macro

James,

I think that will work. Thank you very much. I will try that right now.


--
Damon


"james" wrote:

Sort them first (programmatically if you wish - do a macro record to
see how), then do a find for zero, then delete all rows below.

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
Macro for Copying with conditions MH Excel Discussion (Misc queries) 0 March 10th 10 10:32 PM
macro for excel msg pop up when certain conditions are met Jenny Excel Discussion (Misc queries) 4 August 17th 09 09:27 PM
Macro help: VLOOKUP with conditions uberathlete Excel Programming 4 October 27th 05 06:55 PM
using IF and AND conditions in a macro iamn94 Excel Programming 1 April 17th 05 04:06 PM
Need continuously running macro when conditions are met Cynthia[_3_] Excel Programming 1 February 7th 04 05:07 PM


All times are GMT +1. The time now is 10:34 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"