Results 1 to 21 of 21

Need a macro to delete rows based on multiple conditions

Threaded View

  1. #1
    Registered User
    Join Date
    03-23-2017
    Location
    Harrisburg, Pennsylvania
    MS-Off Ver
    2010
    Posts
    12

    Need a macro to delete rows based on multiple conditions

    Hello!

    I just recently moved into a new job at work and one of my first duties is creating macros. I am woefully inept at this so far and for the most part have been reverse engineering recorded macros to learn.

    My problem I am looking at is that I have an array of six codes in COLUMN B that indicate reversals of payments. Once I see one of these codes in this column I need the macro to check the same row for a value in COLUMN C once it finds that value it needs to move up a row and check to see if the same value is in that row. If all three values are true it needs to delete both columns.

    Column A (DATES)   Column B (CODES)  Column C (PAYMENTS)
    1/1/1990             1(Valid pmt code)                        $200
    1/1/1990             REV(reversal code)                      $200
    1/1/1990             1                                              $200
    1/1/1990             1                                              $523  
    1/1/1990             6(also a reversal code)                $523
    In this example it would delete rows 1,2,4,5 but leave row 3 intact.

    *This is the code I am currently attempting to use.*

    Sub Formatting()
    
        'THIS IS THE CONDITIONAL FORMATTING TO CHECK FOR REVERSALS'
        
        Dim Firstrow As Long
        Dim LastRow As Long
        Dim Lrow As Long
        Dim CalcMode As Long
        Dim ViewMode As Long
        Dim Cell As Range
        Dim Cell1 As String
        Dim Cell2 As String
        Dim Cell3 As String
        
        With Application
            CalcMode = .Calculation
            .Calculation = xlCalculationManual
            .ScreenUpdating = False
        End With
    
        With ActiveSheet
    
            'We select the sheet so we can change the window view
            .Select
    
            ViewMode = ActiveWindow.View
            ActiveWindow.View = xlNormalView
    
            'Turn off Page Breaks, we do this for speed
            .DisplayPageBreaks = False
    
            'Set the first and last row to loop through
            Firstrow = .UsedRange.Cells(1).Row + 1
            LastRow = .UsedRange.Rows(.UsedRange.Rows.Count).Row
            
            'We loop from Lastrow to Firstrow (bottom to top)
            For Lrow = LastRow To Firstrow Step -1
                
                
                'We check the values in the B column'
                
                With .Cells(Lrow, "A")
        
                    If Not IsError(.Value) Then
                    Cell1 = .Cells(Lrow, "A").Value
                    Cell2 = .Cells(Lrow, "B").Value
                    Cell3 = .Cells(Lrow, "C").Value
    
                    If Trim(.Cells(Lrow, "B").Value) = "REV" And .Cells(Lrow - 1, "C").Value = .Cells(Lrow, "C").Value Then
                     Rows(Lrow).EntireRow.Delete
                     Rows(Lrow - 1).EntireRow.Delete
                   
                    
                    End If
    
                    End If
    
                End With
    
            Next Lrow
    
        End With
    Last edited by WorkAccount2; 03-23-2017 at 12:28 PM. Reason: Added missing CODE tags. Please read and follow the Forum Rules, link above in the menu bar. Thanks.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Macro to delete rows based on multiple criteria
    By Andrew E Smith in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-12-2014, 12:17 PM
  2. identifying rows to delete based on multiple conditions
    By DannyGIS in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 06-09-2014, 06:29 PM
  3. [SOLVED] Macro to delete multiple rows based on time of day
    By managermonroe in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-12-2013, 03:00 PM
  4. macro - delete rows based on multiple criteria.
    By ChocksterNo1 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-05-2013, 10:22 AM
  5. [SOLVED] Macro to Delete Rows based on Specific Conditions
    By stockgoblin42 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-28-2013, 05:29 PM
  6. [SOLVED] Macro required to delete rows with multiple conditions
    By bigband1 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-03-2012, 03:53 AM
  7. [SOLVED] VBA code to delete duplicate rows based on multiple conditions
    By pjsween in forum Excel General
    Replies: 5
    Last Post: 06-27-2012, 01:15 PM

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