Consulting

Results 1 to 6 of 6

Thread: Sheet_change is not worked

  1. #1
    VBAX Regular
    Joined
    Feb 2017
    Location
    Hong Kong
    Posts
    33
    Location

    Sheet_change is not worked

    Dear all,

    Can anyone help me urgently ?

    I set a table sheet and database sheet

    1) Database sheet is talking about

    Element 1 column A (key word)
    Element 2 column B (number of information)
    Element 3 column C, D, E.... (Return information under element A)

    2) Table Sheet is set sheet_change VBA

    If column B input anything and match Element 1 then
    Column D will return the information

    3) It is worked after I test the code and saved it. I finished my work on that day through this file.

    But when I opened the file on next day,
    And input any information on Column B in ""table sheet"
    The VBA has not been run automatically.

    I have checked on web, someone set Ctrl G and set something but its still not worked.

    I have created new file and completed the same code again, but it still not worked on the next day.

  2. #2
    Moderator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,192
    Location
    Hi there, can you paste the code you have?
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved

    Excel 365, Version 2403, Build 17425.20146

  3. #3
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    That usually means that a workbook set Application.EnableEvents = False

    Open the Immediate Window (Control-G) and ?Application.EnableEvents to see if it's = True

    Check Personal.xlsm if you have one, and any other workbooks that might be loaded to see if they're turning it off and forgetting to turn it back on
    ---------------------------------------------------------------------------------------------------------------------

    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
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Check that the Excel File type is *.xlsm or *.xlsb, but NOT *.xlsx

    Check that the Workbook, if the correct file type, is macro enabled.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  5. #5
    VBAX Regular
    Joined
    Feb 2017
    Location
    Hong Kong
    Posts
    33
    Location

    Thanks for your help

    Private Sub Worksheet_Change(ByVal Target As Range)
    
    On Error GoTo ENDEND
    
    Application.EnableEvents = True
    
    If Len(Target) <= 0 Then
    Exit Sub
    End If
    
    Dim Haz(30) As String
    
        
    If Target.Column = 2 Then ' Do it when it is Column number 2
    If Target.Row > 3 Then ' Do it when start from Row number 4
    If Len(Target.Value) > 0 Then
    Sheets("Form").Select
                   
    Sheets("Hazard").Activate
    Sheets("Hazard").Range("A2").Select
    Do While Len(ActiveCell.Value) > 0
    If ActiveCell.Value = Target.Value Then
    HazNum = ActiveCell.Offset(0, 1).Value
    For N = 0 To HazNum - 1
    Haz(N) = ActiveCell.Offset(0, N + 2)
    Next N
    Exit Do
    End If
    ActiveCell.Offset(1, 0).Select
    Loop
    Sheets("Form").Select
    Target.Select
    If HazNum > 0 Then
    For N = 0 To HazNum - 1
    ActiveCell.Offset(N, 5).Value = Haz(N) 'Copy to the Column 'G' (5)
    Next N
    ActiveCell.Offset(HazNum + 1, 0).Select
    End If
    End If
    End If
    End If
        
    Exit Sub
    
    ENDEND:
    
    Exit Sub
    
    End Sub
    Last edited by Paul_Hossler; 01-30-2018 at 06:36 PM.

  6. #6
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    Get rid of

    On Error GoTo ENDEND
    and see where it fails

    I'm sure your macro is running EXACTLY the way it's programmed


    Since your macro involves several sheets, I think it'd be better to post a sample workbook since we don't even know what sheet the Change event is on

    For example, if the macro is on the Form worksheet, there's no need to activate another sheet and select a cell. Possibly that's confusing things


    Also you can us the [#] icon to insert CODE tags and paste your macro in between them to set it off and format
    ---------------------------------------------------------------------------------------------------------------------

    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

Posting Permissions

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