Function GetVitals(ID As Long, Age As Long, Optional Weight As Long) As String
GetVitals="ID=" & ID &"Age=" & Age & "Weight=" & Weight
End Function
Sub ShowVitals()
Dim ID As Long, Age As Long,Weight as Long
Debug.Print GetVitals(ID:=5,Age:=20)
Debug.Print GetVitals(ID:=6,Age:=25,Weight:=130)
End Sub
ID=5 Age = 20 Weight=
ID=6 Age = 25 Weight=130
ID=5 Age = 20 Weight=0
ID=6 Age = 25 Weight=130
ID=5 Age = 20 Weight=Null
ID=6 Age = 25 Weight=130
ID=5 Age = 20
ID=6 Age = 25 Weight=130
Sub CalledSub(Surname, Age)
Sub MySub(VarA As Long, ParamArray VarB() As Variant)
MsgBox VarB(0)
End Sub
Sub ShowValue()
Call MySub(10, "First arg", 2, 3.1416)
End Sub
Sub UseSum()
Dim TestArray() As Integer, Total As Integer
ReDim TestArray(1)
TestArray(1) = 6
ReDim TestArray(2)
TestArray(2) = 3
Total = WorksheetFunction.Sum(TestArray)
End Sub
Function SquareIt(ByRef Basis As Integer) As Long
SquareIt = Basis ^ 2
End Function
Dim Result As Long, Side As Integer
Side = 5
Result = Squarelt(Side)
End Sub
Dim Result As Long, Side
Side = 5
Result = SquareIt(Cint(Side))
End Sub
Range("E3:312").Range("B3").Select
_MyVar
My_Var
My-Var
1MyVar
Use the following rules when you name procedures, constants, variables, and arguments in a Visual Basic module: You must use a letter as the first character. You can't use a space, period (.), exclamation mark (!), or the characters @, &, $, # in the name. Name can't exceed 255 characters in length.
Type CBC
Name As String
Next As String
End Type
Type CBC
Name As String
_Next As String
End Type
Type CBC
Name As String
@Option As String
End Type
Type CBC
Name As String
%For As String
End Type
Option Base 0
Sub BuildArray()
Dim MyArray(5) As Integer
Enum TestEnum
Test1
Test2
Test3
End Enum
Dim MyVar As String
Sub AAA()
Dim MyVar As String
MyVar = "Procedure AAA Scope"
End Sub
Sub BBB()
MyVar = "Procedure BBB Scope"
End Sub
Public Property Get HDL() As Double
HDL = pHDL
End Property
Public Property Let HDL(Value As Double)
pHDL = Value
End Property
Property Get HDL() As Double
HDL = Value
End Property
Property Let HDL(Value As Double)
pHDL = Value
End Property
Public Property Get HDL() As Double
HDL = Value
End Property
Public Property Let HDL(Value As Double)
pHDL = Value
End Property
Public Property Get HDL() As Single
HDL = pHDL
End Property
Public Property Let HDL(Value As Double)
pHDL = Value
End Property
Sub MakeErrors()
Dim Y As Variant, Z As Variant
On Error Resume Next
Y = 1 / 0
MsgBox "Y = " & Y
On Error GoTo 0
Z - (0 - 3) ^ 0.5
MsgBox "Z = " & Z
End Sub
Private Sub CommandButton1_Click()
If FoundErrors(Me) Then _
Me.Show
End Sub
Private Sub CommandButton1_Click()
If Not FoundErrors(UserForm1) Then _
Unload UserForm1
End Sub
Private Sub CommandButton1_Click()
Me.Hide
Do While FoundErrors(Me)
Me.Show
Loop
End Sub
Private Sub CommandButton1_Click()
Do While FoundErrors(UserForm1)
UserForm1.show
Loop
End Sub
The first requirement is to make UserForm1 loaded but not visible, therefore, we need Me.Hide, Me in here referring to UserForm1
With Selection
&TypeText Text:="8/24/2019"
&TypeParagraph
&TypeText Text:="1161 Alamosa Drive"
End With
With Selection
.TypeText Text:="8/24/2019"
.TypeParagraph
.TypeText Text:="1161 Alamosa Drive"
End With
With Selection
TypeText Text:="8/24/2019"
TypeParagraph
TypeText Text:="1161 Alamosa Drive"
End With
With Selection:
&TypeText Text:="8/24/2019"
&TypeParagraph
&TypeText Text:="1161 Alamosa Drive"
End With
Sub Example()
Dim MyArr() As Variant
ReDim MyArr(3, 4)
'some code
ReDim Preserve MyArr(4, 4)
End Sub
ReDim Preserve
.ReDim Preserve MyArr(0 To 4, 0 To 4)
.Sub Called(Salary As Long, ParamArray Vals() As Variant)
Sub Called(ParamArray Vals() As Variant, Salary As Long)
Sub Called(Optional Salary As Long, ParamArray Vals() As Variant)
Sub Called(Salary As Long, ParamArray Vals() As String)
UserForm1.Show vbModal
UserForm1.Hwnd = False.
SpecialEffect
property to frmShowModal
ShowModal
property to False.Sub MySub(VarA As String, Optional VarB _
As Variant, Optional VarC As Long)
Sub MySub(VarA As String, Optional VarB _
As Variant, VarC As Long)
Sub MySub(Optional VarA As String, Optional VarB _
As Variant, VarC as Long)
Sub MySub(OPtional VarA As String, VarB _
As Variant, Optional VarC as Long)
Sub Decs() Dim MyFixed As String * 0 MyFixed = "A" MsgBox MyFixed End Sub
Sub Decs() Dim MyInt% * 1 MyInt = 7 MsgBox MyInt End Sub
Sub Decs() Dim MyInt% As Integer * 1 MyInt = 5 MsgBox MyInt End Sub
Sub Decs() Dim MyInt, MyNum As Integer MyInt = "A" MsgBox MyInt End Sub
= CountValues= CountValues
| CountValues| CountValues
: CountValues: CountValues
? CountValues? CountValues
UserForm1.Hwnd = False.
Sub Example() Dim MyArr() As Variant ReDim MyArr(3, 4) 'some code ReDim Preserve MyArr(4, 4)
End Sub Sub Example() Dim MyArr() As Variant ReDim MyArr(3, 4) 'some code ReDim Preserve MyArr(4, 4) End Sub
Do
X = X + 1
i = i + 1
Loop Until i < 5
End Sub
Sub Loopi()
Dim X As Integer, i As Integer
For i = 1 To 5
X = X + 1
Next I
End Sub
Sub Loopi()
Dim X As Integer, i As Integer
Do Until i < 5
X = X + 1
i = i + 1
Loop
End Sub
Sub Loopi()
Dim X As Integer, i As Integer
Do
X = X + 1
i = i + 1
Loop While i < 5
End Sub
Dim Associates As Collection, Assoc As CAssoc, i As Byte
For i = 1 To 200
Set Assoc = New CAssoc
Assoc.Name = Cells(i,1)
Assoc.Number = Cells(i,2)
Associates.Add Assoc
Next i
Set Associates = New Collection
Set Associates = Collection
Redim(Associates(Associates.Count+1))
Redim(Associates _ (Unbound(Associates)+1))
Sub Sumosts(AcctName As String, Amount As Long)
Range("A1") = AcctName
End Sub
If Cars(1).Make="Ford" And Cars (1).MPG > 20
Then Cars(1).Selected = True
ActiveCell.Offset(3,4).Range("A1:E5").Select
Range("b3:f5, c4:d9").Select
Range("b3:f5", "c4:d9").Select