The UDF loadCmdVariable might help you. I changed the properties of the data type, (END scares me as a variable name), but the idea is the same.
Type cmd
begin As Long
halt As Long
End Type
Function loadCmdVariable(ParamArray inputValues() As Variant) As cmd
Select Case TypeName(inputValues(0))
Case "Range"
With inputValues(0)
loadCmdVariable.begin = .Range("a1").Value
loadCmdVariable.halt = IIf(.Rows.Count = 1, .Range("b1").Value, Range("a2").Value)
End With
Case "Byte", "Integer", "Long", "Double", "Single", "Variant", "Boolean"
loadCmdVariable.begin = CLng(inputValues(0))
loadCmdVariable.halt = CLng(inputValues(1))
Case "String"
loadCmdVariable.begin = Val(inputValues(0))
loadCmdVariable.halt = Val(inputValues(1))
End Select
End Function
Sub Test()
Dim xType(1 To 3) As cmd
Dim i As Long
xType(1) = loadCmdVariable(Range("a1:b1"))
xType(2) = loadCmdVariable(Range("a1:a2"))
xType(3) = loadCmdVariable(1, 2)
For i = 1 To 3
MsgBox xType(i).begin & ":" & xType(i).halt
Next i
End Sub
Bookmarks