Consulting

Results 1 to 6 of 6

Thread: Solved: worksheet value change affecting 2 cells

  1. #1

    Wink Solved: worksheet value change affecting 2 cells

    
    
    Private Sub Worksheet_Change(ByVal Target As Range)
    
    Application.ScreenUpdating = False
    'Page 3
     
    If ActiveCell.Address = ThisWorkbook.Sheets("Intervention_3.0").Range("C95").Address Then
        Run "Int3_Update_Page3"
        Exit Sub
    End If
     
    If ActiveCell.Address = ThisWorkbook.Sheets("Intervention_3.0").Range
    ("H95").Address Then
        Range("M95:N95").ClearContents
        Exit Sub
    End If
     
    If ActiveCell.Address = ThisWorkbook.Sheets("Intervention_3.0").Range("M95").Address Then
        Run "Int3_Update_Page3"
        Exit Sub
    End If
    Application.ScreenUpdating = True
    
    End Sub
    this above runs the Int3 Update Page3 if C95 or M95 changes, if H95 changes then M95:N95's contents are clearer. Only one problem on h95 changeing the contents of m95:n95 are cleared but since m95 has changed it runs the update. Can I stop it from doing that

  2. #2
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Khalid, I can't get your first IF statement to work.

    Can you attach an example workbook?
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  3. #3
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Hi khalid79m,

    Try:
    Private Sub Worksheet_Change(ByVal Target As Range)
    'Page 3
    With Application
      .ScreenUpdating = False
      .EnableEvents = False
      With ThisWorkbook.Sheets("Intervention_3.0")
        If ActiveCell.Address = "C95" Or ActiveCell.Address = "M95" Then
          Run "Int3_Update_Page3"
        ElseIf ActiveCell.Address = "H95" Then
          Range("M95:N95").ClearContents
        End If
      End With
      .EnableEvents = True
      .ScreenUpdating = True
    End With
    End Sub
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  4. #4

    hi

    i cant post a workbook as it is confidential info, ill see i can create a dummy sheet.

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim OtherSh As Worksheet

    On Error GoTo ws_exit

    Application.EnableEvents = False
    Application.ScreenUpdating = False
    'Page 3

    Set OtherSh = ThisWorkbook.Sheets("Intervention_3.0")

    If Target.Address = OtherSh.Range("C95").Address Then
    Run "Int3_Update_Page3"
    ElseIf Target.Address = OtherSh.Range("H95").Address Then
    Me.Range("M95:N95").ClearContents
    ElseIf ActiveCell.Address = OtherSh.Range("M95").Address Then
    Run "Int3_Update_Page3"
    End If

    ws_exit:
    Application.EnableEvents = True
    Application.ScreenUpdating = True

    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  6. #6
    again xld you did it..

Posting Permissions

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