If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > VB code for Deleting Rows if a condition is not met

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-05-04, 13:44
mark_s12 mark_s12 is offline
Registered User
 
Join Date: Mar 2004
Posts: 2
VB code for Deleting Rows if a condition is not met

Is it possible to use VB code to delete entire rows in excel if a condition is not met?

I.e if there is no value in column a, (""), is it possible to delete the entire corresponding row.

i.e if no value in cell a2, delete entire row 2
if no value in cell a4, delete entire row 4

Thanks for your help,

Mark
Reply With Quote
  #2 (permalink)  
Old 04-05-04, 16:53
Smitty Smitty is offline
Registered User
 
Join Date: Dec 2003
Location: San Diego, CA
Posts: 153
Welcome to the Board!

If the rows are truly empty and not ="" then you don't need vba.

Select the column

Edit-->Goto-->Special-->Blanks
Edit-->Delete-->Entire Row

If you want a macro then:
Code:
    Columns("A:A").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
Hope that helps,

Smitty
Reply With Quote
  #3 (permalink)  
Old 04-05-04, 17:09
shades shades is offline
Registered User
 
Join Date: Oct 2003
Posts: 1,091
If you want variety, this one will allow you to enter the Column letter and use that as the basis for deleting all empty rows (use with caution, if you have partially used cells above your data).

Code:
Sub DeleteEmptyRows()
'This is one I developed to allow user to enter letter
'of the column that is used for deleting.
Application.ScreenUpdating = False
    Dim myColm As String
    Dim n As String
    Dim rng As Range
    Dim lngRow As Long
    myColm = InputBox("Enter Letter")
    
    If myColm <> "" Then
        n = myColm
        Set rng = Range(n & "1", Range(n & "65536").End(xlUp))
        For lngRow = rng.Rows.Count To 2 Step -1
            If rng(lngRow) = "" Then
                rng(lngRow).EntireRow.Delete
            End If
        Next lngRow
    Else
        Exit Sub
    End If
Application.ScreenUpdating = True

End Sub
__________________
old, slow, and confused
but at least I'm inconsistent!

Rich
(retired Excel 2003 user, 3/28/2008)

How to ask a question on forums
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On