Consulting

Results 1 to 2 of 2

Thread: Help Alter Code

  1. #1
    VBAX Contributor
    Joined
    Dec 2006
    Posts
    193
    Location

    Help Alter Code

    The code below works ,it compares the value in collum "Q" against the corresponding values in collum "J" and shows a message box if the values in collum "J" exceed those in collum "Q" by 40%.I wish to alter the code so that if the value in collum"Q" is a blank or zero the code will not test the values

    Thanks
     
    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Const TEST_COLUMN As String = "A" '<=== change to suit
    Dim i As Long
    Dim LastRow As Long
    Dim msg As String
    Dim msg2 As String
    With ActiveSheet
        LastRow = .Cells(.Rows.Count, TEST_COLUMN).End(xlUp).Row
        For i = 15 To 200
            If i > 129 And i < 143 Then i = 143
            If IsNumeric(.Cells(i, "J").Value) And IsNumeric(.Cells(i, "Q").Value) Then
                If .Cells(i, "J").Value > .Cells(i, "Q").Value * 1.4 Then
                    msg = msg & .Cells(i, "A").Address & " - " & .Cells(i, "A").Value & vbNewLine
                End If
           If .Cells(i, "n").Value > .Cells(i, "x").Value Then
              msg2 = msg2 & .Cells(i, "A").Address & " - " & .Cells(i, "A").Value & vbNewLine
          End If
    End If

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Const TEST_COLUMN As String = "A" '<=== change to suit
    Dim i As Long
    Dim LastRow As Long
    Dim msg As String
    Dim msg2 As String
    With ActiveSheet
        LastRow = .Cells(.Rows.Count, TEST_COLUMN).End(xlUp).Row
        For i = 15 To 200
            If i > 129 And i < 143 Then i = 143
            If IsNumeric(.Cells(i, "J").Value) And IsNumeric(.Cells(i, "Q").Value) And .Cells(i, "Q").Value <> 0 Then
                If .Cells(i, "J").Value > .Cells(i, "Q").Value * 1.4 Then
                    msg = msg & .Cells(i, "A").Address & " - " & .Cells(i, "A").Value & vbNewLine
                End If
                If .Cells(i, "n").Value > .Cells(i, "x").Value Then
                   msg2 = msg2 & .Cells(i, "A").Address & " - " & .Cells(i, "A").Value & vbNewLine
                End If
            End If
        Next i
    End With
    End Sub
    ____________________________________________
    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

Posting Permissions

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