Phil,
Sorry. I had assumed that you were familiar with VBA, seeing that you asked
for code and this is a programming NG.
Open your workbook, press Alt + F11 to open the VBA environment..
Insert a userform.
Put on the form two text boxes, a command button and a label (all from the
toolbox).
In the properties for the label, the command button and the second text box,
go to Visible property and set it to false.
Double click the first textbox and copy and paste this into the code window
on the right.
Private Sub TextBox1_AfterUpdate()
If TextBox1.Value < 0 Or _
TextBox1.Value > =100 Then
MsgBox ("Entry must be zero or a positive number less than 100")
Exit Sub
End If
Sheets("MySheet").Range("B3").Value = TextBox1.Value
TextBox2.Visible = True
End Sub
Private Sub TextBox2_AfterUpdate()
If TextBox2.Value < 0 Or _
TextBox2.Value >= (100 - TextBox1.Value) Then
MsgBox ("Entry must be zero or a positive number less than " _
& (100 - TextBox1.Value))
Exit Sub
End If
Sheets("MySheet").Range("B2").Value = TextBox2.Value
CommandButton1,Visible = True
Label1.Visible = True
Label1.Caption = (100 - TextBox1.Value - TextBox2.Value)
End Sub
Private Sub CommandButton1_Click()
Sheets("MySheet").Range("B1").Value = (100 - TextBox1.Value -
TextBox2.Value)
Unload Me
End Sub
Change MySheet (in 3 places) to the name (Tab) of Your sheet
Under Microsoft Excel Objects in the Project explorer pane,
double click the worksheet that the form is to appear in and
copy and paste this into the code window on the right.
Private Sub Worksheet_Activate()
UserForm1.Show
End Sub
Save & exit.
Reopen the workbook and when you access the sheet, the form will appear.
The first textbox is only thing on the form that is visible initially.
This is the one for the last item (B3).
Any entry in there will be checked for range.
Any entry of less than 0 or 100 or more will be rejected.
A correct entry will result in the second textbox becoming visible.
This is the one for the middle item (B2).
Again, any entry in there will be checked for range.
Any entry of less than 0 or (100 - the value in the first textbox) or more
will be rejected.
A correct entry will result in the label and command button becoming
visible.
The label caption will be the value of (100 - the value in the first
textbox - the value in the second textbox)
I've made this a label (not a text box) so the user cannot change the value
in it.
Clicking on the command button will put the value of the caption in B1 and
close the form.
Once you've got it working, you can add labels to your form telling the user
what is required in each textbox
and you can change the caption of the command button to something like OK or
Exit.
You can also change the colours on the form, textboxes, labels and command
button.
In modern parlance "Sex it up"
HTH
Henry