Consulting

Results 1 to 8 of 8

Thread: Not Working : Worksheet_Change Event

  1. #1
    VBAX Mentor
    Joined
    Nov 2020
    Location
    Cochin, Kerala
    Posts
    314
    Location

    Not Working : Worksheet_Change Event

    Hi
    Request help on the below-
    I have to call a procedure on worksheet change as mentioned below. But my problem here is, the value in "D2" is changed from a user form and that is not triggering the worksheet change event. Codes are in two different workbooks.
    How to call a procedure based on a change in cell value in WB1 by another procedure in WB2?

    Private Sub Worksheet_Change(ByVal Target As Range)
        If Target.Address = "$D$2" Then Call List_Assignments
    End Sub
    Sub ComboBox1_Change()
        BaseWS.Range("D2").Value = ComboBox1.Value
    End Sub
    Thanks in advance!
    Last edited by anish.ms; 04-19-2021 at 02:22 PM.

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    I guess maybe something like:
    Application.Run "'" & Workbooks(2).Path & "\RunMyMacros.xlsm'!Module1.List_Assignments"

  3. #3
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,727
    Location
    Maybe ...

    Don't use Worksheet_Change event, and pass the value that you put into D2 as a parameter to ListAssignments



    Sub ComboBox1_Change()
        BaseWS.Range("D2").Value = ComboBox1.Value
        Call List_Assignments (ComboBox1.Value)
    
    End Sub
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  4. #4
    VBAX Mentor
    Joined
    Nov 2020
    Location
    Cochin, Kerala
    Posts
    314
    Location
    Thanks!
    It worked
    Sub combb_vertical_Change()
        BaseWS.Range("D2").Value = combb_vertical.Value
        combb_assignment.Value = ""
        Application.Run ("'Time Sheet Data.xlsb'!List_Assignments")
        combb_assignment.List = BaseWS.Range("D4:D" & BaseWS.Range("D4").End(xlDown).Row).Value
    End Sub

  5. #5
    VBAX Mentor
    Joined
    Nov 2020
    Location
    Cochin, Kerala
    Posts
    314
    Location
    Thanks Paul!
    I got your point but not sure how to do it.

  6. #6
    VBAX Mentor
    Joined
    Nov 2020
    Location
    Cochin, Kerala
    Posts
    314
    Location
    Request if someone can check my codes and suggest if any better way of doing it. Currently it is working, but I'm sure it can be done in a matured way as I have prepared it based on my basic understanding and searching on the web.

    There are two workbooks
    (1) Time Sheet - Form.xlsm - This will be finally saved as an add-in and will be used by me and my department staffs
    (2) Time Sheet Data.xlsb - Used for storing data from the above form. This file will be located in OneDrive.

    Thanks in advance!
    Attached Files Attached Files

  7. #7
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,727
    Location
    These are the highlights, but search for !!!! in both WB projects. I used !!!! as a marker for lines I changed

    '!!!
        Call Application.Run("'Time Sheet Data.xlsb'!List_Assignments", combb_vertical.Value)
    and

    '!!!! 1. Added Thisworkbook
    '!!!! 2. Added 'dot' to Rows
    '!!!! 3. Added parameter to List_Assignments
    
    
    '!!!!
    Sub List_Assignments(Vert As String)
        Dim lastrow As Long, i As Long, x As Long
        Application.EnableEvents = False
        lastrow = Range("L4").End(xlDown).Row
        ThisWorkbook.Sheets("Base").Range("D4:D50").Clear
        x = 4
        With ThisWorkbook.Sheets("Base")
            For i = 4 To lastrow
    '!!!!
                If (.Cells(i, 12) = Vert) And (.Cells(i, 15) = "Open") Then
                    .Cells(x, 4) = .Cells(i, 13).Value
                    x = x + 1
                End If
            Next i
            .Range("D3", .Range("D" & .Rows.Count).End(xlUp)).Sort _
                         Key1:=.Range("D3"), Header:=xlYes
        If x = 4 Then .Range("D4").Value = "No Assignments Found"
        End With
        
        Call EndOfListAssignments
        Application.EnableEvents = True
    End Sub
    See if these changes work
    Attached Files Attached Files
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  8. #8
    VBAX Mentor
    Joined
    Nov 2020
    Location
    Cochin, Kerala
    Posts
    314
    Location
    Thanks a lot Paul for your time and support

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •