I am trying to have a sub in VBA to call for another sub by passing the i value using the for loop. The problem is when u run the forLoop() sub, there is an error ByRef Type Mismatch. I am just trying out this example method to see if it works so that i can put into my bigger macro.
I tried to add the ByVal method but the error still remains. Someone please help me.
The forLoop sub
Public Sub forLoop()
For i = 1 To 3
Call Fetch_data(i)
Next i
End Sub
The Fetch_data() sub
Sub Fetch_data(num As Integer)
Dim data As String
Dim myCellValue As range
Dim myCellValue1 As range
Dim sht As String
Set sht = "mySheet" & num
Set myCellValue = sht.range("J6")
Set myCellValue1 = sht.range("J8")
myCellValue1.Value = myCellValue.Value
End Sub