PC Review


Reply
Thread Tools Rate Thread

Deleting rows when certain cells are blank

 
 
Matt G
Guest
Posts: n/a
 
      23rd Mar 2009
Hi,

I am using this code to delete the row if the cell in column A is blank.
Dim i, j As Integer
Set starta = ActiveSheet.Range("a2")
LR = ActiveSheet.Range("a" & Rows.Count).End(xlUp).Offset(1, 0).Row
For i = LR To 0 Step -1
If starta.Offset(i, 0).Value = 0 Then starta.Offset(i, 0).EntireRow.Delete
Next i

I would then like to delete a row if the cells in columns B, C, D, and E are
all blank even if the cell in column A is not blank

Any ideas?
 
Reply With Quote
 
 
 
 
Bernie Deitrick
Guest
Posts: n/a
 
      23rd Mar 2009
Matt,

Set starta = ActiveSheet.Range("a2")
LR = ActiveSheet.Range("a" & Rows.Count).End(xlUp).Offset(1, 0).Row
For i = LR To 0 Step -1
If starta.Offset(i, 0).Value = 0 Or _
Application.CountA(starta.Offset(i, 1).Resize(1, 4)) = 0 _
Then starta.Offset(i, 0).EntireRow.Delete
Next i

HTH,
Bernie
MS Excel MVP


"Matt G" <(E-Mail Removed)> wrote in message
news:F2FF438A-1C24-4E93-BEFD-(E-Mail Removed)...
> Hi,
>
> I am using this code to delete the row if the cell in column A is blank.
> Dim i, j As Integer
> Set starta = ActiveSheet.Range("a2")
> LR = ActiveSheet.Range("a" & Rows.Count).End(xlUp).Offset(1, 0).Row
> For i = LR To 0 Step -1
> If starta.Offset(i, 0).Value = 0 Then starta.Offset(i, 0).EntireRow.Delete
> Next i
>
> I would then like to delete a row if the cells in columns B, C, D, and E are
> all blank even if the cell in column A is not blank
>
> Any ideas?



 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      23rd Mar 2009
Give this macro a try...

Sub DeleteRowsIfBtoEareBlank()
Dim LR As Long, i As Long, R As Range
On Error Resume Next
With ActiveSheet
LR = .Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious).Row
For i = LR To 1 Step -1
Err.Clear
Set R = .Range("B" & i & ":E" & i).SpecialCells(xlCellTypeBlanks)
If Err.Number = 0 Then
If R.Count = 4 Then .Rows(i).Delete
End If
Next
End With
End Sub

--
Rick (MVP - Excel)


"Matt G" <(E-Mail Removed)> wrote in message
news:F2FF438A-1C24-4E93-BEFD-(E-Mail Removed)...
> Hi,
>
> I am using this code to delete the row if the cell in column A is blank.
> Dim i, j As Integer
> Set starta = ActiveSheet.Range("a2")
> LR = ActiveSheet.Range("a" & Rows.Count).End(xlUp).Offset(1, 0).Row
> For i = LR To 0 Step -1
> If starta.Offset(i, 0).Value = 0 Then starta.Offset(i,
> 0).EntireRow.Delete
> Next i
>
> I would then like to delete a row if the cells in columns B, C, D, and E
> are
> all blank even if the cell in column A is not blank
>
> Any ideas?


 
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
Re: Selecting Blank Cells then deleting those rows Rick Rothstein Microsoft Excel Programming 0 17th Dec 2009 04:35 PM
RE: Selecting Blank Cells then deleting those rows Gary''s Student Microsoft Excel Programming 0 17th Dec 2009 04:11 PM
RE: Selecting Blank Cells then deleting those rows Ryan H Microsoft Excel Programming 0 17th Dec 2009 04:11 PM
Deleting rows with blank cells Ron de Bruin Microsoft Excel Programming 15 7th Apr 2006 08:00 AM
Deleting rows with blank cells =?Utf-8?B?QmF0bWFu?= Microsoft Excel Worksheet Functions 9 16th Feb 2005 04:15 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:27 PM.