+ Reply to Thread
Results 1 to 9 of 9

a subroutine to check entries

Hybrid View

  1. #1
    Registered User
    Join Date
    07-20-2018
    Location
    Quezon City, Philippines
    MS-Off Ver
    Excel 2013
    Posts
    84

    a subroutine to check entries

    say, in column A to D, I want to check if the data entered in A1 is higher than D1 -
    meaning: value at column A should not be higher than corresponding row in column D.
    is it Workbook_Change or Workbook_SelectionChange that will manage the checking?
    how do we write the code?
    many many thanks

  2. #2
    Valued Forum Contributor
    Join Date
    09-30-2018
    Location
    Vlaams Brabant Belgium
    MS-Off Ver
    365
    Posts
    456

    Re: a subroutine to check entries

    Hi LFKim2018,

    That should be in the vba part of the sheet you want to check

    Private Sub Worksheet_Change(ByVal Target As Range)
     
    End Sub
    Grtz

  3. #3
    Registered User
    Join Date
    07-20-2018
    Location
    Quezon City, Philippines
    MS-Off Ver
    Excel 2013
    Posts
    84

    Re: a subroutine to check entries

    Mr. Joske920
    thank you for your reply.
    could you help me with the code for checking row in column A should not be higher than corresponding row in column D
    many thanks..


    Private Sub Worksheet_Change(ByVal Target As Range)
        If Not Intersect(Target, Range("A:D")) is Nothing Then     '*** this syntax is wrong pls correct
             If Target.row("A") > Target.row("D") Then
                 MsgBox "Cell A greater than Cell D Not allowed!", vbCritical
                 Exit Sub
            End If 
        End If
    End Sub

  4. #4
    Valued Forum Contributor
    Join Date
    09-30-2018
    Location
    Vlaams Brabant Belgium
    MS-Off Ver
    365
    Posts
    456

    Re: a subroutine to check entries

    Hi LFKim2018,

    This is going to help you get past that error

    Private Sub Worksheet_Change(ByVal Target As Range)
       If Not Intersect(Target, Range("A:A")) Is Nothing Then
          If IsNumeric(Target.Value) Then
             If Target > Target.Offset(0, 3) Then
                MsgBox "Cell A" & Target.Row & " greater than Cell D" & Target.Row & " Not allowed!", vbCritical
                Target.Value = vbNullString
                Target.Select
                Exit Sub
             End If
          End If
       End If
    End Sub
    Grtz
    Last edited by Joske920; 10-07-2018 at 07:43 AM.

  5. #5
    Registered User
    Join Date
    07-20-2018
    Location
    Quezon City, Philippines
    MS-Off Ver
    Excel 2013
    Posts
    84

    Re: a subroutine to check entries

    Mr, Joske920
    if this not a violation of the forum policy..
    can I request for one more check on the code?
    if target is greater than the above row - not allowed.
    ex: A3 > A2 or A10>A9 = not allowed
    many many thanks..

  6. #6
    Registered User
    Join Date
    07-20-2018
    Location
    Quezon City, Philippines
    MS-Off Ver
    Excel 2013
    Posts
    84

    Re: a subroutine to check entries

    I think I got it.
    kindly confirm...
    many thanks

    Private Sub Worksheet_Change(ByVal Target As Range)
        If Not Intersect(Target, Range("A:A")) Is Nothing Then
            If IsNumeric(Target.Value) And Target.Row > 1 Then
                If Target > Target.Offset(-1, 0) Then
                    MsgBox "Cell A" & Target.Row & " greater than Cell A" & Target.Row - 1 & " Not allowed!", vbCritical
                    Target.Value = vbNullString
                    Target.Select
                    Exit Sub
                End If
            End If
        End If
    End Sub

  7. #7
    Valued Forum Contributor
    Join Date
    09-30-2018
    Location
    Vlaams Brabant Belgium
    MS-Off Ver
    365
    Posts
    456

    Re: a subroutine to check entries

    Hi LFKim2018,

    Did you want to check if the A cell to be checked against D or not ?
    you have removed that and replaced by checking the previous row in the same column

    also your change is not doing what you want Target should be NOT greater then previous row

    Private Sub Worksheet_Change(ByVal Target As Range)
       If Not Intersect(Target, Range("A:A")) Is Nothing Then
          If IsNumeric(Target.Value) Then
             If Target > Target.Offset(0, 3) Target < Target.Offset(-1, 0) Then
                MsgBox "Cell A" & Target.Row & " greater than Cell D" & Target.Row & " Not allowed!", vbCritical
                Target.Value = vbNullString
                Target.Select
                Exit Sub
             End If
          End If
       End If
    End Sub
    Please try to completely explain your needs, of what you expect it to do.
    That way we can make it do that from the first time we put time in it

    Grtz

  8. #8
    Registered User
    Join Date
    07-20-2018
    Location
    Quezon City, Philippines
    MS-Off Ver
    Excel 2013
    Posts
    84

    Re: a subroutine to check entries

    thank you for your reply.
    the A to D check is in one sheet. It worked just fine. (thank you..)
    the checking of A column only is in another (the latter code).
    so two codes.
    hope it is clear.
    many thanks..

  9. #9
    Registered User
    Join Date
    07-20-2018
    Location
    Quezon City, Philippines
    MS-Off Ver
    Excel 2013
    Posts
    84

    Re: a subroutine to check entries

    Mr. Joske920
    it worked perfectly!
    thank you very very much..

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 10
    Last Post: 07-22-2018, 04:00 PM
  2. Determining which subroutine is calling another subroutine?
    By jplank in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-17-2016, 01:05 PM
  3. Replies: 2
    Last Post: 01-19-2006, 06:00 AM
  4. Check for double entries in a row
    By JE McGimpsey in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 09-06-2005, 10:05 PM
  5. Check for double entries in a row
    By JE McGimpsey in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-06-2005, 05:05 PM
  6. Check for double entries in a row
    By Pierrot Robert in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 03:05 PM
  7. [SOLVED] Check for double entries in a row
    By Pierrot Robert in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 01:05 AM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1