Dependent cell data validation

Noreen12123

New Member
Joined
Oct 7, 2015
Messages
1
Hi everyone (I'm new)!

I have an issue I cannot seem to figure out.

-So I have 2 cells, B1 and B2 say.
-If B2 is 0 I need B1 to stay 0 as well, but I need an error message to pop up if someone changes it.
-If B2 is >0 B1 can be whatever manually entered number you want.

So my steps to doing this were to select B1, go into data validation, Allow: Custom, and I wrote an IF statement as follows
=IF(B2=0,0,B1) ... and set up the error message.

The error message is coming up basically whenever I change B1 now even if B2 is not 0.

I think the if statement may be wrong, but hopefully one of you knows?
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Try putting this in the worksheet code module:

Code:
[COLOR=#0000ff]Option Explicit[/COLOR]

[COLOR=#0000ff]Private Sub [/COLOR]Worksheet_Change([COLOR=#0000ff]ByVal [/COLOR]Target [COLOR=#0000ff]As[/COLOR] Range)

[COLOR=#0000ff]If[/COLOR] Target.Row = 2 [COLOR=#0000ff]And [/COLOR]Target.Column = 2[COLOR=#0000ff] And [/COLOR]Range("B2") = 0[COLOR=#0000ff] Then[/COLOR]
    Range("B1") = 0
[COLOR=#0000ff]End If[/COLOR]

[COLOR=#0000ff]End Sub[/COLOR]

If B2 <> 0 Then the value of B1 is not effected. However if B2 = 0 Then the procedure sets B1 = 0
 
Upvote 0
One option is to use Data Validation.

Go to the Data tab. Select cell B1. Click on Data Validation --> Data Validation. On the Settings tab, under Allow: select Custom. In the formula box, enter:
=B2<>0

Then go to the Error Alert tab and put your message in the Error message box.

HTH
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,693
Members
448,979
Latest member
DET4492

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