+ Reply to Thread
Results 1 to 9 of 9

Multiple Conditions with If Statements in VBA

  1. #1
    Registered User
    Join Date
    02-09-2016
    Location
    Marietta, GA
    MS-Off Ver
    2013
    Posts
    17

    Multiple Conditions with If Statements in VBA

    Sample Workbook.xlsx

    I'm new to VBA and coding in general. I have tried to combine bits and pieces of others' code I found online to create a macro that will look through 3 different columns and if all the conditions exist, eliminate the row where all three conditions are true. (Condition 1 is C2= "Ready"; Condition 2 is H2 = "Clinical"; Condition 3 is D2 does not equal "Tech Start")

    Below is the code I've currently got, but it isn't working.
    Sub EliminateTechTesting()
    'Identifies the Lines with clinical techs choosing any status other than tech start
    Dim LR As Long, i As Long
    LR = Range("C" & Rows.Count).End(xlUp).Row
    LR = Range("D" & Rows.Count).End(xlUp).Row
    LR = Range("H" & Rows.Count).End(xlUp).Row
    For i = LR To 1 Step -1
    If Range("C2" & i).Value = "Ready" And Range("H2" & i).Value = "Clinical" And Range("D2" & i).Value <> "Tech Start" Then Rows(i).Delete
    Next i
    End Sub

    Any help would be very, very much appreciated.
    Last edited by GSU1972; 03-21-2016 at 03:07 PM.

  2. #2
    Valued Forum Contributor
    Join Date
    02-06-2014
    Location
    N/A
    MS-Off Ver
    N/A
    Posts
    373

    Re: Multiple Conditions with If Statements in VBA

    Please upload an example workbook.

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

    Re: Multiple Conditions with If Statements in VBA

    Does this help?

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    02-09-2016
    Location
    Marietta, GA
    MS-Off Ver
    2013
    Posts
    17

    Re: Multiple Conditions with If Statements in VBA

    Attached is sample worksheet in my original post. Thanks
    Last edited by GSU1972; 03-21-2016 at 03:10 PM.

  5. #5
    Registered User
    Join Date
    02-09-2016
    Location
    Marietta, GA
    MS-Off Ver
    2013
    Posts
    17

    Re: Multiple Conditions with If Statements in VBA

    Unfortunately, this was not the solution.

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

    Re: Multiple Conditions with If Statements in VBA

    Maybe you meant?
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    02-09-2016
    Location
    Marietta, GA
    MS-Off Ver
    2013
    Posts
    17

    Re: Multiple Conditions with If Statements in VBA

    Opps, I may have mistyped. iIn the original spreadsheet, the columns are actually C, K, an D (I've left some out for privacy protection).
    The problem seems more to be in trying to use IF AND & THEN in combination. See below what was highlighted on the debug:
    If Range("C" & i).Value = "Ready" And Range("K" & i).Value = "Clinical" And Range("D" & i).Value <> "Tech Start" Then

    Thanks

  8. #8
    Valued Forum Contributor
    Join Date
    02-06-2014
    Location
    N/A
    MS-Off Ver
    N/A
    Posts
    373

    Re: Multiple Conditions with If Statements in VBA

    Hi, try this, where cells(x, [corresponding column number]) references the cell instead of range.

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    02-09-2016
    Location
    Marietta, GA
    MS-Off Ver
    2013
    Posts
    17

    Re: Multiple Conditions with If Statements in VBA

    I used the code, but got the error "Next without For"

+ 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] Syntax for formula that uses multiple conditions inside of multiple IF statements
    By njmiller31 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-02-2013, 11:55 AM
  2. multiple if statements/conditions syntax
    By kamelkid2 in forum Excel General
    Replies: 3
    Last Post: 01-13-2011, 10:18 AM
  3. [SOLVED] If Statements / Multiple Possible Conditions
    By jmg81485 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-01-2010, 02:52 AM
  4. Replies: 12
    Last Post: 05-15-2009, 08:38 AM
  5. Multiple conditions in nested IF statements
    By havfunonline2 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-09-2009, 05:36 AM
  6. If statements with multiple conditions
    By afathi in forum Excel General
    Replies: 4
    Last Post: 04-22-2008, 04:30 PM
  7. IF Statements, Multiple Conditions
    By DiamondCutter in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-21-2005, 11:25 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