+ Reply to Thread
Results 1 to 4 of 4

Delete_Rows_Based_On_Multiple_Criteria()

  1. #1
    Registered User
    Join Date
    04-23-2013
    Location
    United States
    MS-Off Ver
    Excel 2013
    Posts
    16

    Delete_Rows_Based_On_Multiple_Criteria()

    Trying to build a VBA Macro to delete rows based on multiple conditions.

    I have an excel table with Columns [A - AD]
    I also have 8778 Rows (Which is different each time

    Column P has data manufacturer Example: Dell Computer
    Column K has data price Example: 210.00

    The macro has to delete rows if the following conditions are not met.

    Delete row if (Column A = 'Dell Computer' AND Column B <= 250.00)


    Sub sbDelete_Rows_Based_On_Multiple_Criteria()
    Dim LastRow As Long
    Dim iCntr As Long

    'Find LastRow Using UsedRange
    sht.UsedRange 'Refresh UsedRange
    LastRow = sht.UsedRange.Rows(sht.UsedRange.Rows.Count).Row


    .... Not sure what to do here? ...


    End Sub



    Any help would be greatly appreciated. I search around for an answer, but came up short. Each application is so unique.

  2. #2
    Valued Forum Contributor
    Join Date
    05-14-2012
    Location
    Unknown
    MS-Off Ver
    Unseen
    Posts
    429

    Re: Delete_Rows_Based_On_Multiple_Criteria()

    Why not just switch on AutFilter, filter on columns A and B and select and delete the visible rows.

    Record a macro while you do it.

  3. #3
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Delete_Rows_Based_On_Multiple_Criteria()

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  4. #4
    Registered User
    Join Date
    04-23-2013
    Location
    United States
    MS-Off Ver
    Excel 2013
    Posts
    16

    Re: Delete_Rows_Based_On_Multiple_Criteria()

    Thank you very much for the help. This totally go me going in the right direction.
    Here was the final VBA Code I used. Please let me know if you see any corrections.

    Sub sbDelete_Rows_Based_On_Multiple_Criteria()

    Application.ScreenUpdating = False
    Sheets(1).Select 'Select Sheet
    Range("A1").Select
    On Error Resume Next
    Set mylastcell = Cells(1, 1).SpecialCells(xlLastCell)
    mylastcelladd = Cells(mylastcell.Row, mylastcell.Column).Address
    myrange = "A1:" & mylastcelladd 'Change to A2 if you want to avoid selecting header row
    With Range(myrange).CurrentRegion
    'With Range("A1").CurrentRegion
    .AutoFilter Field:=2, Criteria1:="General Electric" 'Column B
    .AutoFilter Field:=1, Criteria1:="<=249.999" 'Column A
    .Offset(1).SpecialCells(xlCellTypeVisible).Delete Shift:=xlShiftUp 'Do not process header row
    End With
    ActiveSheet.AutoFilterMode = False
    Application.ScreenUpdating = True

    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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