tiredofit
Well-known Member
- Joined
- Apr 11, 2013
- Messages
- 1,924
- Office Version
- 365
- 2019
- Platform
- Windows
Is it OK to mix data types?
In the code above, despite SheetCol being defined as a Variant, I know (just believe me!) that it'll always return an Integer.
(The reason I've declared it as a Variant is that if it was declared as an Integer, I would need error handling if no match was found).
As can be seen, j is declared as an Integer and its value set to be equal to SheetCol.
Does VBA implicitly convert different data types?
Thanks
Code:
Function Matching(ByRef Startstring As Variant, ByRef Sheetname As Worksheet, ByRef Ref As String)
As Variant
Matching = Application.Match(Startstring, Sheetname.Range(Ref), 0)
End Function
Sub Start()
Dim SheetCol As Variant
SheetCol = Matching(Startstring:="Sheet", Sheetname:=Me, Ref:=MyRow & ":" & MyRow)
Dim j As integer
j = SheetCol
End Sub
In the code above, despite SheetCol being defined as a Variant, I know (just believe me!) that it'll always return an Integer.
(The reason I've declared it as a Variant is that if it was declared as an Integer, I would need error handling if no match was found).
As can be seen, j is declared as an Integer and its value set to be equal to SheetCol.
Does VBA implicitly convert different data types?
Thanks
Last edited: