|
![]()
|
||||||||||
Double click on the command button you inserted, and copy this code into the area between Sub CommandButton1_Click() and End Sub:
This ensures that blank text boxes are not allowed
If TextBox1.Value = "" Or TextBox2.Value = "" Then
MsgBox "Nothing entered!", vbExclamation, "Test Message"
Else
' this is what should happen if there is text in the boxes
' and remember that any words following a " ' " are excluded from VB code
MsgBox TextBox1.Value, vbExclamation, TextBox2.Value
End If
Double click the textbox and insert this code:
Range("A1").Value = TextBox1.Value
Go back up
Double click on the command button and insert
this code between the subs:
If Range("A1").Value > 50 then
' do nothing!!!
Else
MsgBox "You just entered " & Range("A1").Value & " into textbox1 and cell A1", vbinfo, "Cool Huh?"
End If
Copy this code into the declarations, and you
can change the minimum and maximum values
Const CurMax = 1000000
Const CurMIn = 0
Dim uNum As Variant
Double click on TextBox1, delete all text
that you see, and paste all of this code into the cleared area:
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
' Define the textbox you want to test
uNum = TextBox1.Value
'If uNum is blank than do nothing
If uNum = "" Then
'If it is not blank check to see a number was entered
Else
If IsNumeric(uNum) Then
' Now if the entry is within the defined ranges
If uNum >= CurMIn And uNum <= CurMax Then
' if it is within the defined ranges
' do something with the number like this
Range("A1").Value = TextBox1.Value
End If
' If the entry is less than the defined
' range tell the user and enter 0 as the default entry
If uNum < CurMIn Then
MsgBox "The value entered is less than zero", vbExclamation, "Validation"
TextBox1.Value = 0
Range("A1").Value = TextBox1.Value
Else
' if the number was greater than the
' defined range tell the user and enter 0 as a default
If uNum > CurMax Then
MsgBox "Higher the max value", vbExclamation, "Validation"
TextBox1.Value = 0
Range("A1").Value = TextBox1.Value
End If
End If
Else
' if the entry was an alpha character
' tell the user what went wrong and correct the error
MsgBox "Alphabetic values are not allowed", vbExclamation, "Validation"
TextBox1.Value = 0
Range("A1").Value = TextBox1.Value
End If
End If
End Sub
Copy this code into the area between Sub CommandButton1_Click
and End Sub
'Declare the varaibles for this macro
Dim Msg, Style, Title, fivebucks
' Define here your message, and the title of the yes/no question prompt
Msg = "Do have have 5 bucks in your pocket?"
Style = vbYesNo
Title = "Five buck question!!!"
' Let's call this question fivebucks since it sounds cool
fivebucks = MsgBox(Msg, Style, Title)
' So now the message "Do you have..." will be diplayed
' and the user has a yes or no choice
If Validate = vbYes Then
TextBox1.Value = "COOL"
Else
TextBox1.Value = "DAMN"
End If
Copy this in between the Sub CommandButton1_Click
and End Sub
On Error Resume Next
MyAppID = Shell("C:\Program Files\Microsoft Office\Office\word.exe", 1)
AppActivate MyAppID
Try to read and understand the code that follows, and the footnotes are at the end of the actual code:
SolverReset1 SolverOk2 SetCell:="$A$1", MaxMinVal:=13, ValueOf:="0", ByChange:="$A$1" SolverAdd CellRef:="$C$1", Relation:=24, FormulaText:="$D$1"5 SolverOk SetCell:="$A$1", MaxMinVal:=1, ValueOf:="0", ByChange:="$A$1" SolverSolve6 UserFinish:=True7
Copy this code into the area between Sub
CommandButton1_Click and End Sub
SolverReset
SolverOk SetCell:="$A$1", MaxMinVal:=1, ValueOf:="0", ByChange:="$A$1"
SolverAdd CellRef:="$C$1", Relation:=2, FormulaText:="$D$1"
SolverOk SetCell:="$A$1", MaxMinVal:=1, ValueOf:="0", ByChange:="$A$1"
SolverSolve UserFinish:=True
Go back up