使用VBA ,自定义函数以后,调用时报错:argument not optional
Public Function Find_Col_ID(ByVal rowID, ByVal objWorkBook, ByVal objWorkSheet, ByVal strColName) As Integer
objWorkBook.Activate
objWorkSheet.Select
objWorkSheet.Cells(1, 1).Select
Cells.Find(what:=strColName, after:=ActiveCell, LookIn:=xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False).Select
If Selection.Row = rowID Then
Find_Col_ID = Selection.Column
Else
Find_Col_ID = 0
End If
End Function
Sub Test()
Dim columnnum As Integer
columnnum = Find_Col_ID("姓名")
MsgBox columnnum
End Sub