Data Validation Via VBA Code

Rather than storing the value in A2, you could use Application.Undo and avoid the Selection Change event. The back and forth between the two events triggering each other is too congested.
 
Upvote 0

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Rather than storing the value in A2, you could use Application.Undo and avoid the Selection Change event. The back and forth between the two events triggering each other is too congested.

thank you but thats not the point here.. the Code even when shortened, the problem persists... any work around will be appreciated :).. my new shortened code in my previous post
PHP:
Private Sub Worksheet_Change(ByVal Target As Range) 
If Intersect(Target, Range("match")) Is Nothing Then Exit Sub 
If Target.Value > Range("D" & Target.Row).Value Then 
    MsgBox "Not Enough Fund" 
    Exit Sub 
Else 
MsgBox "Transaction Made" 
End If 
End Sub
 
Upvote 0
1) Please do not use PHP tags when you post. It fouls up the copy paste from message board to Excel. Use the code tag (#) instead.

2) The posted code seemed to work fine for me. Entering a large number brought up the "Not engough Fund" box, a small number "Transaction made".

If you are having problems, did your Application.EnableEvents get "stuck" on False during a debugging error/reset?
 
Last edited:
Upvote 0
2) The posted code seemed to work fine for me. Entering a large number brought up the "Not engough Fund" box, a small number "Transaction made".

it only partly works....
Suppose Target.Row Value in Column D = 100
you said you typed value less than D (for instance =5) "Transaction made"
but have you typed value = 90 which is again less than D's Value (100) but i bet it will show "Not enough Fund"
 
Last edited:
Upvote 0
I looked at it again, and found the source of the problem.

C4 has 200
G4 has 100 and H4:K4 are empty

D4 has the formula =C4-E4 (shows 100)
E4 has the formula =SUM(G4:K4) (shows 100)


Entering 90 into H4, triggers the calculation so that the value in E4 is 190 and the value in D4 is 10.

Then the Change event (triggered by the entry into H4, not the resulting calculations) runs, and since D4 (10) is not greater than H4 (90), the "Not enough fund" message shows.

The problem is that with the testing cell (D4) being dependent on the value in Target, a circular reference has been set up.
 
Upvote 0
You might consider changing the Validation test to "If col D < 0 then Bad". The Validation could be done by either the Change envent or by built-in Validation. In either case, this test will be made AFTER the formulas have calculated the newly entered value into their results.
 
Upvote 0
You might consider changing the Validation test to "If col D < 0 then Bad". The Validation could be done by either the Change envent or by built-in Validation. In either case, this test will be made AFTER the formulas have calculated the newly entered value into their results.

thats wonderful Mike...
i guess you figure that one out.. i am looking to do with Vba and not data validation tool in excel. you know im not so advance in Vba;). could u be kind enough to add "If col D < 0 then Bad" in my code if not much trouble..
Thank U.
 
Upvote 0

Forum statistics

Threads
1,225,371
Messages
6,184,583
Members
453,244
Latest member
Todd Luet

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