I copied a code that worked well in VBA module to UserForm since I need to combine some actions defined in userform. Now I got stuck when executing the following part, with error message 'Application-defined or object-defined error'
Sub test()
Dim Myworkbook As workbook
Dim Myid As Variant
Set Myworkbook = ThisWorkbook
Myid=1
Myref=FinRef(Myworkbook, "Ref", Myid)
End Sub
Function FinRef(myfile As Workbook, InputSheet As String, Ref_ID As Variant)
Dim I, k, LinkFrom, Description As Integer
Dim Linkdescrip As String
FinRef = ""
LinkFrom = 1
Description = 8
Linkdescrip = 7
For I = 2 To 3000
k = myfile.Sheets(InputSheet).Cells(I, LinkFrom)
If k = Ref_ID Then
FinRef = FinRef & myfile.Sheets(InputSheet).Cells(I, Linkdescrip) & myfile.Sheets(InputSheet).Cells(I, Description)
End If
Next I
End Function
Though there are lots of ppl who experienced the same problem, I couldn't find solution fit for me. Any tips?
Thanks a lot!
Dim I, k, LinkFrom, Description As Integerdeclares 3 variants and only 1 integer. I doubt that was you intent. Also, please post a minimal reproducible example which people can actually run to see your exact error. There seems to be a disconnect between your question and your actual problem.