Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Delete Macro based on condition in Two Columns

Hello,

I have these two macros. there similar one delete rows based on value in
Col. C and the other deletes rows based on values in Col A. Now I want to
combine the two so I only have one macro to run. here are both Macros

Sub DeleteBlankPCCRows()
Dim i As Long, LastRow As Long
Application.ScreenUpdating = False

'finds last used row in column A
LastRow = Range("A" & Rows.Count).End(xlUp).Row

'begin loop to check each row
For i = LastRow To 7 Step -1
'if cell= blank, delete row
If Cells(i, "A") = "" Then Rows(i).Delete
Next i

Application.ScreenUpdating = True
End Sub

And the second one is

Sub DeleteUnusedRows()

Dim i As Long, LastRow As Long
Application.ScreenUpdating = False

'finds last used row in column C
LastRow = Range("C" & Rows.Count).End(xlUp).Row

'begin loop to check each row
For i = LastRow To 7 Step -1
'if cell= 0, delete row
If Cells(i, "C") = 0 Then Rows(i).Delete
Next i

Application.ScreenUpdating = True
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Delete Macro based on condition in Two Columns

Hadi,

This now combines the 2 but note I made a change to column C. In your code
If Cells(i, "C") = 0 Then Rows(i).Delete
would delete the row if the cell was empty OR zero.

In my code it must contain a 0 to be deleted

Sub DeleteBlankPCCRows()
Dim i As Long, LastRow As Long
Application.ScreenUpdating = False

'finds last used row in column A
LastRow = Range("A" & Rows.Count).End(xlUp).Row

'begin loop to check each row
For i = LastRow To 7 Step -1

'if cell= blank, delete row
If Cells(i, "A") = "" Or Cells(i, "C") < "" _
And Cells(i, "C") = 0 Then Rows(i).Delete

Next i

Application.ScreenUpdating = True
End Sub


Mike

"Hadi" wrote:

Hello,

I have these two macros. there similar one delete rows based on value in
Col. C and the other deletes rows based on values in Col A. Now I want to
combine the two so I only have one macro to run. here are both Macros

Sub DeleteBlankPCCRows()
Dim i As Long, LastRow As Long
Application.ScreenUpdating = False

'finds last used row in column A
LastRow = Range("A" & Rows.Count).End(xlUp).Row

'begin loop to check each row
For i = LastRow To 7 Step -1
'if cell= blank, delete row
If Cells(i, "A") = "" Then Rows(i).Delete
Next i

Application.ScreenUpdating = True
End Sub

And the second one is

Sub DeleteUnusedRows()

Dim i As Long, LastRow As Long
Application.ScreenUpdating = False

'finds last used row in column C
LastRow = Range("C" & Rows.Count).End(xlUp).Row

'begin loop to check each row
For i = LastRow To 7 Step -1
'if cell= 0, delete row
If Cells(i, "C") = 0 Then Rows(i).Delete
Next i

Application.ScreenUpdating = True
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Delete Macro based on condition in Two Columns

Great! it works.

thanks Mike.

"Mike H" wrote:

Hadi,

This now combines the 2 but note I made a change to column C. In your code
If Cells(i, "C") = 0 Then Rows(i).Delete
would delete the row if the cell was empty OR zero.

In my code it must contain a 0 to be deleted

Sub DeleteBlankPCCRows()
Dim i As Long, LastRow As Long
Application.ScreenUpdating = False

'finds last used row in column A
LastRow = Range("A" & Rows.Count).End(xlUp).Row

'begin loop to check each row
For i = LastRow To 7 Step -1

'if cell= blank, delete row
If Cells(i, "A") = "" Or Cells(i, "C") < "" _
And Cells(i, "C") = 0 Then Rows(i).Delete

Next i

Application.ScreenUpdating = True
End Sub


Mike

"Hadi" wrote:

Hello,

I have these two macros. there similar one delete rows based on value in
Col. C and the other deletes rows based on values in Col A. Now I want to
combine the two so I only have one macro to run. here are both Macros

Sub DeleteBlankPCCRows()
Dim i As Long, LastRow As Long
Application.ScreenUpdating = False

'finds last used row in column A
LastRow = Range("A" & Rows.Count).End(xlUp).Row

'begin loop to check each row
For i = LastRow To 7 Step -1
'if cell= blank, delete row
If Cells(i, "A") = "" Then Rows(i).Delete
Next i

Application.ScreenUpdating = True
End Sub

And the second one is

Sub DeleteUnusedRows()

Dim i As Long, LastRow As Long
Application.ScreenUpdating = False

'finds last used row in column C
LastRow = Range("C" & Rows.Count).End(xlUp).Row

'begin loop to check each row
For i = LastRow To 7 Step -1
'if cell= 0, delete row
If Cells(i, "C") = 0 Then Rows(i).Delete
Next i

Application.ScreenUpdating = True
End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Delete Macro based on condition in Two Columns

Glad to help and thanks for the feedback


"Hadi" wrote:

Great! it works.

thanks Mike.

"Mike H" wrote:

Hadi,

This now combines the 2 but note I made a change to column C. In your code
If Cells(i, "C") = 0 Then Rows(i).Delete
would delete the row if the cell was empty OR zero.

In my code it must contain a 0 to be deleted

Sub DeleteBlankPCCRows()
Dim i As Long, LastRow As Long
Application.ScreenUpdating = False

'finds last used row in column A
LastRow = Range("A" & Rows.Count).End(xlUp).Row

'begin loop to check each row
For i = LastRow To 7 Step -1

'if cell= blank, delete row
If Cells(i, "A") = "" Or Cells(i, "C") < "" _
And Cells(i, "C") = 0 Then Rows(i).Delete

Next i

Application.ScreenUpdating = True
End Sub


Mike

"Hadi" wrote:

Hello,

I have these two macros. there similar one delete rows based on value in
Col. C and the other deletes rows based on values in Col A. Now I want to
combine the two so I only have one macro to run. here are both Macros

Sub DeleteBlankPCCRows()
Dim i As Long, LastRow As Long
Application.ScreenUpdating = False

'finds last used row in column A
LastRow = Range("A" & Rows.Count).End(xlUp).Row

'begin loop to check each row
For i = LastRow To 7 Step -1
'if cell= blank, delete row
If Cells(i, "A") = "" Then Rows(i).Delete
Next i

Application.ScreenUpdating = True
End Sub

And the second one is

Sub DeleteUnusedRows()

Dim i As Long, LastRow As Long
Application.ScreenUpdating = False

'finds last used row in column C
LastRow = Range("C" & Rows.Count).End(xlUp).Row

'begin loop to check each row
For i = LastRow To 7 Step -1
'if cell= 0, delete row
If Cells(i, "C") = 0 Then Rows(i).Delete
Next i

Application.ScreenUpdating = True
End Sub

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
Slow Macro - Delete Row Based on Condition-Modified Ron DeBruin Ma ScottMSP Excel Programming 3 January 28th 09 09:33 PM
how to delete a row based on a condition ya Excel Programming 2 December 17th 08 03:59 PM
Delete rows based on more than one condition. thomas Excel Programming 3 September 24th 08 02:20 PM
Macro to delete rows based on a condition Darrilyn Excel Worksheet Functions 1 September 6th 07 12:12 AM
Delete Columns based on a condition Joel Mills Excel Programming 3 August 6th 04 07:21 PM


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