Consulting

Results 1 to 2 of 2

Thread: Recognizing linked changes, Worksheet_Change(ByVal Target As Range)

  1. #1
    VBAX Newbie
    Joined
    Jul 2014
    Posts
    1
    Location

    Recognizing linked changes, Worksheet_Change(ByVal Target As Range)

    I am trying to create code for a message box to appear when a value within my range is greater then 40. All of the values within my range are SUM() commands from the same sheet. The message box appears if I physically change the value of the cell (example, changing "SUM(G1:H16)" to simply "44") but will not change if I only change the values in the SUM() range (same example, just changing the numeric values in range H1:H16). I also do not want it to loop, if there are multiple errors I would want only one message box to appear. Below is the code that I have so far:

    Private Sub Worksheet_Change(ByVal Target As Range)
    Const FirstRow As Long = 57
    Const LastRow As Long = 63
    Dim myColumns As String
    myColumns = "G:V"
    If Target.Row >= FirstRow And Target.Row <= LastRow Then
            If Target > 40 Then
                MsgBox "This change has put you over 40 hours for the week.", vbOKOnly, "Warning"
            Else
            End If
        End If
    End Sub

    Thank you!
    Cody

  2. #2
    VBAX Regular
    Joined
    Jul 2014
    Posts
    20
    Location

    Cool Code

    Quote Originally Posted by noff32 View Post
    I am trying to create code for a message box to appear when a value within my range is greater then 40. All of the values within my range are SUM() commands from the same sheet. The message box appears if I physically change the value of the cell (example, changing "SUM(G1:H16)" to simply "44") but will not change if I only change the values in the SUM() range (same example, just changing the numeric values in range H1:H16). I also do not want it to loop, if there are multiple errors I would want only one message box to appear. Below is the code that I have so far:

    Private Sub Worksheet_Change(ByVal Target As Range)
    Const FirstRow As Long = 57
    Const LastRow As Long = 63
    Dim myColumns As String
    myColumns = "G:V"
    If Target.Row >= FirstRow And Target.Row <= LastRow Then
            If Target > 40 Then
                MsgBox "This change has put you over 40 hours for the week.", vbOKOnly, "Warning"
            Else
            End If
        End If
    End Sub
    Thank you!
    Cody
    Add this code to the worksheet you want to be checked:

    Private Sub Worksheet_Change(ByVal Target As Range)
    ' Filters column 7 and 8 (G & H)
    ' and checks only on rows 1 to 16
    If Target.Column > 6 And Target.Column < 9 And Target.Row < 17 Then
        If Target.FormulaR1C1 > 40 Then
            MsgBox "Value greater than 40"
        End If
    End If
    End Sub

Tags for this Thread

Posting Permissions

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