"Sub or Function not defined" VBA



VBA新手此处

当我运行代码时,我收到错误"Sub or Function not defined"。这发生在我的一个子例程中。第一行由调试器高亮显示为黄色。

Sub Description(Row As Integer, SheetName As String)
With Worksheet(SheetName)
.Cells(Row, 1) = ActiveCell.Offset(0, -3)   
.Cells(Row, 2) = ActiveCell.Offset(0, -2)   
.Cells(Row, 3) = ActiveCell.Offset(0, -1)
End With
End Sub

这个子程序接收一个数字和一个字符串。我想将特定描述复制到另一个工作表"SheetName"中。这是子程序调用之前的一段代码。"x"的值是在循环范围之外声明的。

string_temp = "Sheet2"
ActiveSheet.Cells(i, 5).Select
Call Description(x, string_temp)
x= x + 1

感谢您的帮助!

With Worksheet(SheetName)应为With Worksheets(SheetName)

同样将Row As Integer更改为Row as LongIntegerVBA中实际上稍微慢一些,因为编译器将其转换为Long进行处理。

相关内容

最新更新