+ Reply to Thread
Results 1 to 9 of 9

Worksheet_Change based on 2 conditions

  1. #1
    Registered User
    Join Date
    12-22-2022
    Location
    missiissauga, on
    MS-Off Ver
    365
    Posts
    23

    Worksheet_Change based on 2 conditions

    I have a code. It works well. However I need to make a change.
    My code is based on having "completed" in column F
    I cant figure out how to ADD a 2nd condition.
    I need it to also have "Running Repair" in column E

    Can someone please help?




    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim f As Range
    Dim resp As VbMsgBoxResult
    Dim i As Long

    If Not Intersect(Target, Range("F:F")) Is Nothing Then
    If Target.Count > 1 Then Exit Sub
    If Target.Value = "Completed" Then
    resp = MsgBox("Is unit returned to service?", _
    vbYesNo + vbQuestion)
    If resp = vbYes Then
    Set f = Range("I:J").Find("RETURNED TO SERVICE", , xlValues, xlPart, , , False)
    If Not f Is Nothing Then
    i = f.Row + 2
    Set f = Range("I:J").Find(Range("A" & Target.Row).Value, , xlValues, xlWhole, , , False)
    If Not f Is Nothing Then
    MsgBox "This unit already exists in the section."
    Exit Sub
    End If
    Do While True
    If Range("I" & i).Value = "" Then
    Range("I" & i).Value = Range("A" & Target.Row).Value
    Exit Do
    End If
    i = i + 1
    Loop
    End If
    End If
    End If
    End If
    End Sub

  2. #2
    Valued Forum Contributor rollis13's Avatar
    Join Date
    01-26-2012
    Location
    Cordenons
    MS-Off Ver
    Excel 2016 32bit - Win 11
    Posts
    917

    Re: Worksheet_Change based on 2 conditions

    Add this code at the end of your event macro.
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    12-22-2022
    Location
    missiissauga, on
    MS-Off Ver
    365
    Posts
    23

    Re: Worksheet_Change based on 2 conditions

    Sorry for not being clear, the condition at this moment is column F needs to be "Completed"

    I need it to be column F "Completed" + column E "Running Repair"

    Both conditions have to be at the same time

  4. #4
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,466

    Re: Worksheet_Change based on 2 conditions

    Should be:
    PHP Code: 
    .........declare variables
    If Target.Count 1 Then Exit Sub
    If Intersect(TargetRange("E:F")) Is Nothing Then Exit Sub ' trigger target in E:F only
    If Cells(target.row, "E").value & Cells(target.row, "F").value = "Running RepairCompleted" Then ' 
    combine value if both criteria
    ... main code 
    Quang PT

  5. #5
    Registered User
    Join Date
    12-22-2022
    Location
    missiissauga, on
    MS-Off Ver
    365
    Posts
    23

    Re: Worksheet_Change based on 2 conditions

    what if I want "Running Repair" in column E, and "Completed" in column F?

  6. #6
    Valued Forum Contributor rollis13's Avatar
    Join Date
    01-26-2012
    Location
    Cordenons
    MS-Off Ver
    Excel 2016 32bit - Win 11
    Posts
    917

    Re: Worksheet_Change based on 2 conditions

    So isn't that what @bebo021999 's suggestion was for ?
    Last edited by rollis13; 01-14-2023 at 06:22 PM.

  7. #7
    Registered User
    Join Date
    12-22-2022
    Location
    missiissauga, on
    MS-Off Ver
    365
    Posts
    23

    Re: Worksheet_Change based on 2 conditions

    yes, sorry, I didnt see that post, I was looking at the other one, my mistake

  8. #8
    Valued Forum Contributor rollis13's Avatar
    Join Date
    01-26-2012
    Location
    Cordenons
    MS-Off Ver
    Excel 2016 32bit - Win 11
    Posts
    917

    Re: Worksheet_Change based on 2 conditions

    Thanks for the positive feedback, glad we were able to help.

  9. #9
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,466

    Re: Worksheet_Change based on 2 conditions

    It seems your issue has been solved. Pls mark it as "SOLVED"

+ 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] Worksheet_Change - Cell States (Numeric, Chars, Blank) not hitting conditions?
    By K26 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-27-2020, 05:44 AM
  2. [SOLVED] if formula based on several criteria to extract data based on conditions
    By JEAN1972 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 12-17-2018, 12:46 PM
  3. [SOLVED] Worksheet_Change event - hide/unhide columns based on multiple drop down list
    By Villalobos in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-08-2018, 10:17 AM
  4. [SOLVED] Need help with a Worksheet_Change sub (hide/unhide rows based on cell value)
    By happyfingers in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-21-2017, 02:15 AM
  5. Worksheet_Change based on Cell Dropdown Selection
    By jadown in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-13-2017, 10:32 AM
  6. [SOLVED] Worksheet_Change Macro To Hide Columns Based On A Range But Only When One Cell Is Edited
    By GEANZ in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-08-2013, 07:54 PM
  7. calculation using reference to cells based on conditions
    By shrimic in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-16-2012, 12:32 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