vba “子或函数未定义”错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21548113/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 01:43:27  来源:igfitidea点击:

'sub or function not defined' error

excel-vbavbaexcel

提问by user3270087

I have a problem with Sub or Function not definederror with my program below. could anyone help me solve this?

Sub or Function not defined我的程序有以下错误问题。谁能帮我解决这个问题?

Main Macro:

主要宏:

Private Sub CommandButton1_Click()
    EraseWorkSheetKeepRow1 ("FilteredItems")
     Sheets("SalesData").Select
    Dim i As Integer
    Dim k As Integer
    k = Application.WorksheetFunction.CountA(Range("A:A"))
    For i = 2 To k
        Sheets("SalesData").Select
        If Val(Cells(i, 3)) > Val(TextBox1.Text) Then
          Call Copy1row("SalesData", i, "FilteredItems")
        End If

    Next
End Sub

Sub Routine1 (EraseWorkSheetKeepRow1):

子程序 1 (EraseWorkSheetKeepRow1):

Sub EraseWorkSheetKeepRow1(sheetname As String)
'
' EraseWorkSheetKeepRow1 Macro
' Erase all rows except row 1 for worksheet
    ActiveWorkbook.Sheets(CustomerInfo).Select
    Dim k As Integer
    k = Application.WorksheetFunction.CountA(Range("A:A")) + 1
    Range("A2:C" & k).Select
    Selection.ClearContents
End Sub

Sub Routine2 (Copy1row):

子程序 2(Copy1row):

Sub Copy1row(FromSheet As String, rowno As Integer, ToSheet As String)
'
' Copy1row Macro
    Sheets(CustomerInfo).Select
    Rows(rowno & ":" & rowno).Select
    Selection.Copy
    Sheets(ToSheet).Select
    Dim k As Integer
    k = Application.WorksheetFunction.CountA(Range("A:A")) + 1
    Rows(k & ":" & k).Select
    Selection.PasteSpecial _
        Paste:=xlPasteAll, _
        Operation:=xlNone, _
        SkipBlanks:=False, _
        Transpose:=False
End Sub

回答by user3349290

this error usually has nothing to do with the code itself. Please check that the sub name is not the same as the module name and that you haven't used the same name in another sub as this can cause the definition error.

这个错误通常与代码本身无关。请检查子名称是否与模块名称不同,并且您没有在另一个子中使用相同的名称,因为这会导致定义错误。