RIchavalues
New Member
- Joined
- Feb 24, 2016
- Messages
- 25
- Office Version
- 2019
- Platform
- Windows
Hi All,
I tried my best to fix the issue myself and couldn't figure out for hours and hope I get some help here.
Am trying to pass a variable to a range through another subroutine. If argument is of same datatype, it works. But if multiple datatype, then getting "Type mismatch error 13". Am posting both methods below:
Method1: Below method works fine
Method2:
I have fruits as an example but in real time I have larger value and hence choosing Long datatype.
I really appreciate any help provided.
Thanks,
Richa
I tried my best to fix the issue myself and couldn't figure out for hours and hope I get some help here.
Am trying to pass a variable to a range through another subroutine. If argument is of same datatype, it works. But if multiple datatype, then getting "Type mismatch error 13". Am posting both methods below:
Method1: Below method works fine
Code:
Sub GoMainFunction(var1 As String)
ThisWorkbook.Worksheets("TestData").Select
With ThisWorkbook.Worksheets("TestData")
Range(var1).Select
End With
End Sub
Sub SelectRange()
Call GoMainFunction("A1")
Call GoMainFunction("A5")
End Sub
Method2:
Code:
Function MainFunction(Fruits As Long, var1 As String) As Variant
ThisWorkbook.Worksheets("TestData").Select
Select Case Fruits
Case "APPLE"
With ThisWorkbook.Worksheets("TestData")
Range(var1).Select
End With
Case "ORANGE"
With ThisWorkbook.Worksheets("TestData")
Range(var1).Select
End With
End Select
End Function
Sub SelectRange()
Call MainFunction("APPLE", "A1")
Call MainFunction("ORANGE", "A5")
End Sub
I have fruits as an example but in real time I have larger value and hence choosing Long datatype.
I really appreciate any help provided.
Thanks,
Richa
Last edited: