vba to check row criteria

LFKim2018

Active Member
Joined
Mar 24, 2018
Messages
267
Requesting help for > VBA to check range (C2:G1001),
The Criteria: if C2 and D2 are filled (not empty) then G2 must be > 0 to have a complete entry, if criteria was met then it is "legit"; the cursor should stay at G2 until it is filled with a number. To exit such checking, it is "legit" to erase entry of either C2 or D2 to bypass the checking (because the criteria would now be gone).
This check should only be invoked if there is no entry to G2 whenever C2 & D2 are filled.. and so on..
C2,D2,G2 is just a presentation, it could be any row from 2 to 1001..

Should these 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
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
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
 
Upvote 0
To make it simpler:
range of checking is D2 to G1001
disregard Ci and check only if Di is filled with data - the cursor to go to Gi (both in the same row) awaiting for number greater than zero otherwise a prompt will appear for correct entry. To bypass this check, Di have to be erased to free Gi of mandatory entry.
likewise if Di & Gi are both filled, erasing Gi will not be allowed unless Di is erased first.
to make it clearer still: criteria = Gi must be filled if ever Di is inputed with data (both in the same row). (not vice versa!)
many many many thanks
 
Upvote 0
Good Day!
I would like to share to anyone who might have the same scenario as I did.
Mr. Man Fai Chan provided me with the codes for vba to check row critera, pls see below:
I hope this can help someone, as it did me. Thanks
Private Sub worksheet_change(ByVal Target As Range)
Application.EnableEvents = False
r = Target.Row
c = Target.Column
Select Case c
Case 4
Cells(r, c + 3).Select ' select the corresponding cells in column G
Case 7
If Len(Target) = 0 And Cells(r, c - 3) > 0 Then
MsgBox ("You have to delete column D first")
Application.Undo ' undo the delete
Else
If Val(Target.Value) <= 0 And Cells(r, c - 3) > 0 Then
MsgBox ("Input a postive value")
Target.Select ' select the corresponding cell
End If
End If
End Select
Application.EnableEvents = True
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,250
Members
452,623
Latest member
Techenthusiast

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top