private sub needed

juan1

New Member
Joined
May 17, 2017
Messages
46
I would like a private sub written that does the following:
First a value that is being entered into A1 affects the answer to a formula in A2. I don't want the answer to the formula in A2 be less than 3.
If this occurs A1's input brings a message up and will not let that input happen.

This also happens in B1 effecting, B2 and C1 effecting C2

thanks for any help
Juan
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
In the developer VBE, project left pane, click THISWORKBOOK,
insert the code as shown in image: (there is no image upload)

Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Target.Offset(1, 0).Value < 3 Then
  MsgBox "Result in Row 2 cannot be less than 3"
  Target.Value = 99
End If
End Sub
 
Upvote 0
Probably should have explained a little more, thought I could have improvised.
I don't think I can use offset because actually A1 effects A2, A3 & also A4. If any of those go under 3 the message needs to come up.

also could you add the same happening in column B


thanks again for the help
 
Upvote 0
...because actually A1 effects A2, A3 & also A4.
Can you explain this in a little more detail? If A2 contains a formula, how is A3 linked to it? I thought the user is typing the value into the cells... how is that working when the cell contains a formula?
 
Upvote 0
A2, A3 & A4 are formulas that use an input from A1.
If A1's input effects any of those so the answer to the formulas goes below 3, A1 can not let the input happen.
thanks
 
Upvote 0
I meant in this code. back to the beginning of by request.
thanks

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Target.Offset(1, 0).Value < 3 Then
MsgBox "Result in Row 2 cannot be less than 3"
Target.Value = 99
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,695
Messages
6,126,263
Members
449,307
Latest member
Andile

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