+ Reply to Thread
Results 1 to 4 of 4

If Statement that checks two cells

Hybrid View

  1. #1
    Registered User
    Join Date
    01-31-2014
    Location
    East Coast, England
    MS-Off Ver
    Excel 2010
    Posts
    44

    If Statement that checks two cells

    Hi Ladies and Gents,

    I am trying to check a cell to see if it contains "Deactivation" and if it does check to see if the cell next to it contains "Prepaid" if both are true delete the entire row if either one is not true move on to the next.

    Attached is a sample of my data (some columns blanked out for security reasons.) The code i have currently just deletes anything that is a deactivation.

    
    Sub del_Prepaid_Deact()
    
    
    Dim myDate As Date, aDate, bottomL As Integer, x As Integer, e As Range
    
    
    'Rename Worksheet to "Generated and Todays Date"
        
            myDate = Date + 7 - Weekday(Date)
            aDate = Format(myDate, "dd.mm.yyyy")
            
            Sheet1.Name = "Generated " & aDate
    
    '/Rename Worksheet to "Generated and Todays Date"
            
    ' Remove "Prepaid Deactivations"
        
        On Error Resume Next
            Sheets("Generated " & aDate).Activate
            
                 
            bottomL = Sheets("Generated " & aDate).Range("A" & Rows.Count).End(xlUp).Row: x = 2
         
        For Each e In Sheets("Generated " & aDate).Range("Q1:Q" & bottomL)
            If e.Value = "Deactivation" Then
               e.EntireRow.Delete
                x = x + 1
        End If
          
        Next e
          Columns("A").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
          
    '/Remove "Prepaid Deactivations"
    
    
    End Sub
    Any help greatly received.

    Thank you in advance

    Rich
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor Kamboj's Avatar
    Join Date
    09-25-2014
    Location
    India
    MS-Off Ver
    2003 - 2010
    Posts
    430

    Re: If Statement that checks two cells

    change one line of your code
     If e.Value = "Deactivation" And e.Offset(0, -1) = "Prepaid" Then

  3. #3
    Registered User
    Join Date
    01-31-2014
    Location
    East Coast, England
    MS-Off Ver
    Excel 2010
    Posts
    44

    Re: If Statement that checks two cells

    Thanks Kamboj works a treat.

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: If Statement that checks two cells

    Try:

    Sub del_Prepaid_Deact()
    
    
    Dim myDate As Date, aDate, bottomL As Long, x As Integer, e As Long
    
    'Rename Worksheet to "Generated and Todays Date"
        
            myDate = Date + 7 - Weekday(Date)
            aDate = Format(myDate, "dd.mm.yyyy")
            
            Sheet1.Name = "Generated " & aDate
    
    '/Rename Worksheet to "Generated and Todays Date"
            
    ' Remove "Prepaid Deactivations"
        
        On Error Resume Next
            Sheets("Generated " & aDate).Activate
            
                 
            bottomL = Sheets("Generated " & aDate).Range("A" & Rows.Count).End(xlUp).Row
         
        For e = bottomL To 2 Step -1
            If Cells(e, "Q").Value = "Deactivation" And Cells(e, "P").Value = "Prepaid" Then
               Rows(e).Delete
            End If
        Next e      Columns("A").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
          
    '/Remove "Prepaid Deactivations"
    
    
    End Sub
    Note: When Looping to delete rows you should delete from bottom to top.
    Last edited by JOHN H. DAVIS; 06-22-2015 at 09:05 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 0
    Last Post: 11-21-2014, 05:00 PM
  2. [SOLVED] Formula which checks whether a string is found in a range and checks 2 criteria
    By liranbo in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-30-2012, 05:28 PM
  3. COUNTIF statement with 3 criteria checks
    By Malvaro in forum Excel General
    Replies: 4
    Last Post: 06-04-2006, 06:45 PM
  4. [SOLVED] if-then statement that checks for existence of series 2
    By danz98 in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 08-24-2005, 05:05 PM
  5. [SOLVED] If-then statement that checks for existence of series 2
    By danz98 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-16-2005, 02:05 AM

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