To accept manual data or return a default value based on condition.

Gajendran Yadhav

Board Regular
Joined
Sep 8, 2023
Messages
51
Office Version
  1. 2010
  2. 2007
Platform
  1. Windows
Friends,

I'm working on a worksheet where I've a plenty of data to be validated.

I'm having the column N for entering the monetary value ranging from "0" to actual value.

If column P is equal to "FIR" or "Criminal", then column N should accept only "0" as its value.
if column P is not equal to "FIR" or "Criminal", then it can accept any value greater than "0"

As of now I'm using the Conditional Formatting to highlight in Red (as error) if the condition is satisfied.
=IF(OR(P5="FIR",P5="CRIMINAL")*AND(N5<>0),TRUE,FALSE)

1701753509896.png



Row 5 is the first row of the worksheet. Rows 1 - 4 has some headers and table heads.

A simple Data Validation formula would suffice my need. I'm not much of a techie to use VBA Codes...

Any help is much appreciated. TIA
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
That's not the correct way to use AND(). You can simply change AND(N5<>0) to (N5<>0) since you have no other parameter to AND() it with.
As far as Data Validation goes shouldn't this just be

=AND(N5<>0,OR(P5="FIR",P5="CRIMINAL"))
 
Upvote 0
I believe you are looking for this?:

Libro1
NOPQ
1Monetary ComponentBy / AgainstClassificationData Validation formula
20,00FIR1
35,00FIR0
40,00Criminal1
55,00Criminal0
60,00CD1
75,00CD1
80,00WC1
95,00WC1
Hoja1
Cell Formulas
RangeFormula
Q2:Q9Q2=(N2=0)*((P2="FIR")+(P2="Criminal"))+(P2<>"FIR")*(P2<>"Criminal")
 
Upvote 0
or with AND and OR functions:

Libro1
NOPQ
1Monetary ComponentBy / AgainstClassificationData Validation formula
20,00FIRVERDADERO
35,00FIRFALSO
40,00CriminalVERDADERO
55,00CriminalFALSO
60,00CDVERDADERO
75,00CDVERDADERO
80,00WCVERDADERO
95,00WCVERDADERO
Hoja1
Cell Formulas
RangeFormula
Q2:Q9Q2=OR(AND(N2=0,OR(P2="FIR",P2="Criminal")),AND(P2<>"FIR",P2<>"Criminal"))
 
Upvote 0
That's not the correct way to use AND(). You can simply change AND(N5<>0) to (N5<>0) since you have no other parameter to AND() it with.
As far as Data Validation goes shouldn't this just be

=AND(N5<>0,OR(P5="FIR",P5="CRIMINAL"))
Dear Special-K99,

Initially I tried with this formula for it being short...unfortunately, it didn't work.

Column N should accept value as 0 only when column P is either FIR or Criminal.
For other values of P, N can be anything inclusive of 0.
 
Upvote 0
or with AND and OR functions:

Libro1
NOPQ
1Monetary ComponentBy / AgainstClassificationData Validation formula
20,00FIRVERDADERO
35,00FIRFALSO
40,00CriminalVERDADERO
55,00CriminalFALSO
60,00CDVERDADERO
75,00CDVERDADERO
80,00WCVERDADERO
95,00WCVERDADERO
Hoja1
Cell Formulas
RangeFormula
Q2:Q9Q2=OR(AND(N2=0,OR(P2="FIR",P2="Criminal")),AND(P2<>"FIR",P2<>"Criminal"))
Dear Felixstraube,

Thanks for giving your opinion.
I'm looking to validate the column "N" itself.
You have given for validating whether it is true or false.

The actual expectation is that column N should accept its value as 0 if the column P is either "FIR" or "Criminal".
for other values of column P, column N can accept any value inclusive of 0.
 
Upvote 0
Dear Special-K99 & Felixstraube,

by reading our forums of various topics and sorting to my needs,
I came up with this formula and it works.

=IF(OR(P5="FIR",P5="Criminal"),N5=0,ISNUMBER(N5))

I have also added the custom error message to pop-up on validation failure.

1701856282141.png


Thus the problem solved.
-----------------------------------------------------------------------------------------

and in continuation, I got another query.
Since column N is filled first and the column P, Excel accepts any value in column N first.
say if i enter 1 in N5 and subsequently enter FIR or Criminal in P5, nothing happens.

any possible solution to sort this out..??

I cannot interchange the columns such that column N goes next to column P.

further, column O is a list function and column P is dependent list of column O.

can column P have two data validation ?
I'm thinking of to have, column P should accept the entry only if column N is blank (empty).

or column N should accept any entry only if column P is filled with its data.


any other solution to prevent such entry will be helpful.

as of now I'm using Conditional Formatting option to highlight the both the cells (N & P) in RED denoting an error.
but no control over the data entry.
1701856226910.png


Thanks.
 
Upvote 0
Thanks for giving your opinion.
I'm looking to validate the column "N" itself.
You have given for validating whether it is true or false.

The actual expectation is that column N should accept its value as 0 if the column P is either "FIR" or "Criminal".
for other values of column P, column N can accept any value inclusive of 0.
I provided the formula you should use in your data validation. I wrote it in the column Q just so you could see it. Use the formula in Q2 in you data validation for N2 and drag down. It should work as expected.
 
Upvote 0
I provided the formula you should use in your data validation. I wrote it in the column Q just so you could see it. Use the formula in Q2 in you data validation for N2 and drag down. It should work as expected.
Thanks dear. Anyways, the formula which I've mentioned is working fine for me... I think I would leave it as it is.

Do you see any additional advantage in using this formula which you suggested..??
I'll keep learning.

and I'll be much obliged if you could help with the other query as well....

TIA
 
Upvote 0
Either formula will work just fine. Yours also checks that it is a number so it wont allow text to be entered.

To check for data in column P try this:

Excel Formula:
=AND(P2 <> "", IF(OR(P2 = "FIR", P2 = "Criminal"), N2 = 0, ISNUMBER(N2)))

And you could show error message like "Please entere a classification first. If classification is either FIR or Criminal, monetary component should be zero."

Libro1
NOPQ
1Monetary ComponentBy / AgainstClassificationData Validation formula
20FIRVERDADERO
35FIRFALSO
4abcFIRFALSO
50CriminalVERDADERO
65CriminalFALSO
7abcCriminalFALSO
80CDVERDADERO
95CDVERDADERO
10abcCDFALSO
110WCVERDADERO
125WCVERDADERO
13abcWCFALSO
140FALSO
155FALSO
16abcFALSO
Hoja1
Cell Formulas
RangeFormula
Q2:Q16Q2=AND(P2<>"",IF(OR(P2 = "FIR", P2 = "Criminal"), N2 = 0, ISNUMBER(N2)))
 
Upvote 0
Solution

Forum statistics

Threads
1,223,952
Messages
6,175,596
Members
452,657
Latest member
giadungthienduyen

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