I'm 4 days old to VBA so still working things out!
I have managed to create this subroutine for a form im working on.
First off, i think it works but any obvious problems (including good practice things) please to point them out. This is an ammalgamation of various bits ive picked up from google and from common sense!
Could someone explain the highlighted bits of code (ones ive put a ' before, but all lines are used in my script, its just to point them out)
The first line can anyone completely explain what each part of the object_Exit() bit does, ive searched and search and cant work it out. Why cant i just put
like i have done on TextBox3_Change() (which i use to update other textboxes, havnt looked at whether this can be included in the code below yet.
second line
there are a few things with this area of code:
if an If statement is concluded on one line does it negate the need for an End If?
would it make sense if i put an Else statement to deal with vbYes
I think i understand the rest. Although if anyone has any better / more concise / more efficient ways of doing the same thing I am all ears :D
Thanks for your help! :D
I have managed to create this subroutine for a form im working on.
First off, i think it works but any obvious problems (including good practice things) please to point them out. This is an ammalgamation of various bits ive picked up from google and from common sense!
Could someone explain the highlighted bits of code (ones ive put a ' before, but all lines are used in my script, its just to point them out)
The first line can anyone completely explain what each part of the object_Exit() bit does, ive searched and search and cant work it out. Why cant i just put
Code:
'Private Sub TextBox3_Exit()
second line
there are a few things with this area of code:
if an If statement is concluded on one line does it negate the need for an End If?
would it make sense if i put an Else statement to deal with vbYes
I think i understand the rest. Although if anyone has any better / more concise / more efficient ways of doing the same thing I am all ears :D
Code:
'Private Sub TextBox3_Exit(ByVal Cancel As MSForms.ReturnBoolean)
With TextBox3
If IsNull(.text) = True Or IsNumeric(.text) = False Then
If MsgBox("Invalid entry. Please enter a numerical value for '" + .Tag + "' to continue", vbCritical, "ERROR") = vbOK Then .Value = Val("4.18")
Else
If Val(.Value) <> Val("4.18") Then
' If MsgBox("Are you sure? This is a Universal Constant! **** like this doesn't change overnight!", vbYesNo + vbExclamation, "Really?") = vbNo Then .Value = Val("4.18")
Exit Sub
End If
End If
End With
TextBox9.Value = (Val(TextBox8.text) / ((Val(TextBox4.text) - Val(TextBox5.text)) * Val(TextBox3.text)))
End Sub
Thanks for your help! :D