i write a code as follow:
Call search(xx, yy, "APM Output", ">> State Scalars", label1)
label1:
...........
this the script of Sub search
Sub search(row As Variant, col As Variant, wkst As String, str As String, label_num As Name)
For row = 1 To 100
For col = 1 To 100
strTemp = Worksheets(wkst).Cells(row, col).Value
If InStr(strTemp, str) <> 0 Then
GoTo label_num
End If
Next
Next
End Sub
i want to call sub search(..) firstly, and then go to label1.
The problem is that is says that “ByRef argument type mismatch” for label_num.What should be the correct type for label_num in Sub search(..,..,..,label_num)?
i add some original script, these are what I want to convert into a sub()
For xx = 1 To 100
For yy = 1 To 100
strTemp = Worksheets("APM Output").Cells(xx, yy).Value
If InStr(strTemp, ">> State Scalars") <> 0 Then
GoTo label1
End If
Next
Next
label1:
For uu = 1 To 100
For vv = 1 To 100
strTemp = Worksheets("APM Output").Cells(uu, vv).Value
If InStr(strTemp, ">> GPU LPML") <> 0 Then
GoTo label2
End If
Next
Next
label2:
For mm = 1 To 100
For nn = 1 To 100
strTemp = Worksheets("APM Output").Cells(mm, nn).Value
If InStr(strTemp, ">> Limits and Equations") <> 0 Then
GoTo label3
End If
Next
Next
As a good practise, please avoid using label at all cost!
I am going to answer you just modifying your code, I guess you want to save the values of
xx,yy,uu,vv,mm,nn
the following code is how to avoid using label
to make your function into a sub, simply do
and call it 3 times,
for example: