+ Reply to Thread
Results 1 to 3 of 3

Need help to delete rows based on cell content

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-08-2006
    Posts
    203

    Need help to delete rows based on cell content

    I need a macro that will delete rows when column A doesnt contain certain things.
    Here is a sample
    Distribution	Center	6125C	
    Purchase	Order	Number:	1202053395
    DATE,	PLEASE	*SHIP
    ==============================		
    Line	#	Buyer
    1	950694	82687864236
    3	950715	82687862003
    8	969736	82687112108
    Summary	Level	Allowances:
    Total	Cubic	Feet:
    Total	Weight:	n/a
    Total	Line	Items:
    I want all rows deleted unless column A contains "Distribution", "Purchase", or a Number 1-9

    Result:
    Distribution	Center	6125C	
    Purchase	Order	Number:	1202053395
    1	950694	82687864236
    3	950715	82687862003
    8	969736	82687112108
    Thank you

  2. #2
    Forum Expert
    Join Date
    01-12-2007
    Location
    New Jersey
    Posts
    2,127
    Try this code and report back:

    Sub Delete_Rows()
        Dim LastRow As Long
        
        LastRow = Cells(Rows.Count, 1).End(xlUp).Row
        
        Application.ScreenUpdating = False
        For i = LastRow To 2 Step -1
            If Cells(i, 1) < 1 Or Cells(i, 1) > 9 And UCase(Cells(i, 1)) <> "DISTRIBUTION" And UCase(Cells(i, 1)) <> "PURCHASE" Then
                Cells(i, 1).EntireRow.Delete
            End If
        Next i
        Application.ScreenUpdating = True
    End Sub

  3. #3
    Forum Contributor
    Join Date
    08-08-2006
    Posts
    203
    Quote Originally Posted by BigBas
    Try this code and report back:
    That did it!

    Thank you very much!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1