Forum Discussion

Lorenzo Kim's avatar
Lorenzo Kim
Bronze Contributor
Jun 17, 2018

VBA to check for completeness of row entry

Requesting for help for VBA for the following scenario:

let us assume i is the number of rows from 2 to 1001 (checking range C2:G1001)

The criteria is this:

if Ci & Di are filled with data then Gi should be > 0 to have a complete row entry otherwise after an entry of zero or less, a MsgBox appears to prompt for correct entry.

if Ci & Di are filled, the cursor should automatically go to Gi .

To escape this check, either Ci or Di can be erased to clear the preset criteria.

following the above logic if Ci,Di,Gi are filled, Gi can never be erased unless Ci or Di is erased first.

 

Should this check be in:

Private Sub Worksheet_SelectionChange(ByVal Target As Range) or
Private Sub Worksheet_Change(ByVal Target As Range)?

I hope this is clear enough.
many thanks

 

2 Replies

  • Lorenzo Kim's avatar
    Lorenzo Kim
    Bronze Contributor

    To make it much simpler:

    The Criteria now is > if ever Di is inputted with data, the cursor should go directly to Gi and await an entry of greater than zero otherwise a prompt will appear for correct entry. Di & Gi is in the same row.

    criteria: Gi got to have a value of greater than zero if ever Di is inputted with data. 

    To bypass this check, Di have to be erased. The range of checking is from Row 2 to 1001 (range D2:G1001).

    following this logic, if Di & Gi are filled, Gi can not be erased unless Di is erased first.

    No 'vice-versa' - meaning there is no criteria for Di to be required if ever Gi is inputted. Just from Di to Gi only. Maybe this VBA is makeable.....(under what sub should the code be placed?)

    many many thanks

     

  • Lorenzo Kim's avatar
    Lorenzo Kim
    Bronze Contributor

    Maybe my post on this subject is not clear.

    I don't know which of the following will capture the event:

    Private Sub Worksheet_SelectionChange(ByVal Target As Range) or
    Private Sub Worksheet_Change(ByVal Target As Range)?

    the scenario: (i is any row number) whenever Ci and Di (in the same row) are inputted with data, the cursor should automatically go to Gi and await an entry of greater than zero otherwise a prompt for correct entry will appear. Either Ci or Di can be erased to bypass this check. 

    following the logic, if Ci,Di & Gi are all filled with data, Gi can not be erased unless either Ci or Di is erased first. I need a vba for this. 

    many many thanks

Resources