我想知道是否有人可以幫助我。我創建了一個非常簡單的用戶表單來記錄信息。然而,我的問題是,當其中一個字段爲空時,我收到一條錯誤消息:工作表功能錯誤子或功能未定義
未定義子或函數。
Private Sub CommandButton1_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Data")
'find first empty row in database
iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
'check for a Name number
If Trim(QueryType.Value) = "" Then
QueryType.SetFocus
MsgBox "Please complete the form"
Exit Sub
End If
'copy the data to the database
ws.Cells(iRow, 1).Value = Format(Now, "DD/MM/YYYY")
ws.Cells(iRow, 2).Value = Format(Now, "HH:MM")
ws.Cells(iRow, 3).Value = Application.UserName
ws.Cells(iRow, 4).Value = CType.Value
ws.Cells(iRow, 5).Value = IName.Value
ws.Cells(iRow, 6).Value = QType.Value
ws.Cells(iRow, 7).Value = 1
ws.Cells(iRow, 8).Value = Format(Date, "MMM-YY")
'ws.Cells(iRow, 9).Value = Application.WorksheetFunction.VLookup(InternalName.Value, Sheet2.Range("C1:D23"), 2, 0)
'ws.Cells(iRow, 9).Value = Application.WorksheetFunction.IfError(VLookup(InternalName.Value, Sheet2.Range("C1:D23"), 2, 0), "")
ws.Cells(iRow, 10).Value = Application.WorksheetFunction.VLookup(InternalName.Value, Sheet2.Range("C1:E23"), 3, 0)
ws.Cells(iRow, 11).Value = "IB"
Unload Me
MsgBox "Data added", vbOKOnly + vbInformation, "Data Added"
End Sub
的問題是在任,我收到錯誤註釋掉線之一。我只收到,如果我離開下拉框空。如果填充,則不會發生錯誤。我可以輕鬆地爲「不適用」選擇一個額外的菜單選項,但寧可只是空白。有沒有人有任何建議?
哪一行在調試時突出顯示? – Kelaref
@Kelaref無論哪個iRow,9我都取消註釋。對不起,我應該說。我原本只是把它看作是一個虛擬主機。當我得到錯誤時,我認爲Iferror函數可以解決問題,但它會產生相同的結果。 – MBrann