+ Reply to Thread
Results 1 to 2 of 2

VBA If Then with Multiple OR & AND conditions

  1. #1
    Registered User
    Join Date
    01-02-2020
    Location
    LA, Cali
    MS-Off Ver
    365
    Posts
    9

    VBA If Then with Multiple OR & AND conditions

    I am trying to copy/paste rows from one worksheet to another if they meet multiple and/or criteria:

    If the idea_status is NOT "closed", "deleted", OR "draft" and
    the idea_submitted_date is LTE 12/31/2018 and
    the next_action_date is LTF 12/31/2020
    Then copy/paste.

    I can get it working if only using the AND conditions. Once I try to add the OR it pulls back all the results. Any direction would be greatly appreciated!


    Private Sub CommandButton1_Click()

    a = Worksheets("Team Tracker Dump").Cells(Rows.Count, 1).End(xlUp).Row

    For i = 2 To a

    If Worksheets("Team Tracker Dump").Cells(i, 4).Value <> "Deleted" Or _
    Worksheets("Team Tracker Dump").Cells(i, 4).Value <> "Closed" Or _
    Worksheets("Team Tracker Dump").Cells(i, 4).Value <> "Draft" Then
    If Worksheets("Team Tracker Dump").Cells(i, 6).Value <= #12/31/2018# Then
    If Worksheets("Team Tracker Dump").Cells(i, 11).Value <= #12/31/2020# Then
    Worksheets("Team Tracker Dump").Rows(i).Copy
    Worksheets("Extraction").Activate
    b = Worksheets("Extraction").Cells(Rows.Count, 1).End(xlUp).Row
    Worksheets("Extraction").Cells(b + 1, 1).Select
    ActiveSheet.Paste

    End If
    End If
    End If

    Next

    Application.CutCopyMode = False
    Worksheets("Team Tracker Dump").Activate
    Worksheets("Team Tracker Dump").Cells(1, 1).Select
    MsgBox ("Task is done")

    End Sub
    Attached Files Attached Files

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,445

    Re: VBA If Then with Multiple OR & AND conditions

    You can't use Or with not equals. They're mutually exclusive. Deleted is not equal to Closed, and Closed is not equal to Draft. So, if you Or them, the overall condition will be True. You need to And them together.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


+ 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. [SOLVED] Help for IF conditions with multiple Conditions (scenario more than 5 conditions)
    By meily_o26 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 12-16-2019, 02:13 AM
  2. Replies: 29
    Last Post: 01-01-2017, 10:25 AM
  3. Replies: 2
    Last Post: 01-14-2016, 03:53 PM
  4. [SOLVED] Vlookup - Country conditions (Multiple conditions)
    By dluhut in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 04-26-2013, 11:42 AM
  5. Insert multiple values from seperate table based on multiple conditions
    By drakesong in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 02-28-2011, 06:04 PM
  6. Replies: 1
    Last Post: 12-05-2010, 04:39 AM
  7. How to multiple conditions to validate more than 2 conditions to .
    By Bhuvana Govind in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-28-2005, 04:06 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