Results 1 to 3 of 3

Delete row if 1st cell not equal to defined value?

This is a discussion on Delete row if 1st cell not equal to defined value? within the Excel Questions forums, part of the Question Forums category; New to VBA - I have a template I use to reformat an exported report so it will import into ...

  1. #1
    Board Regular
    Join Date
    Mar 2008
    Location
    Pennsylvania
    Posts
    964

    Default Delete row if 1st cell not equal to defined value?

    New to VBA-
    I have a template I use to reformat an exported report so it will import into another database. One of the things I need to do is divide this report into 26 separate reports.

    What I would like to do is create a macro that will delete any rows where the first cell is not equal to a given value, for example 10100. My thinking is that I will create a macro for each of the 26 possible values and save as after I run each delete macro.
    This report does have a header that I need to keep.
    The length (number of rows) changes monthly and I'd rather not alter the macro each month.

    Help?

  2. #2
    Board Regular iggydarsa's Avatar
    Join Date
    Jun 2005
    Location
    One of the Blue States
    Posts
    1,535

    Default Re: Delete row if 1st cell not equal to defined value?

    Code:
    Sub test()
    For i = Range("A" & Rows.Count).End(xlUp).Row To 2 Step -1
        If Range("A" & i).Value <> 10100 Then Rows(i).Delete shift:=xlUp
    Next i
    End Sub

  3. #3
    Board Regular
    Join Date
    Mar 2008
    Location
    Pennsylvania
    Posts
    964

    Default Re: Delete row if 1st cell not equal to defined value?

    You rock! I should have just posted 2 hours ago!

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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


DMCA.com