将变量传递给子

时间:2012-09-18 13:15:38

标签: excel excel-vba vba

当我编写Test1子的最后一行时,我收到一个错误。它说“期待=”。有什么想法吗?

Sub selectByUsedRows(usedCol As String, selectCol As String)
n = Range(usedCol).End(xlDown).Row
Range(selectCol & "1:" & selectCol & n).Select
End Sub

Sub Test1()
Dim a As String, b As String
a = "A"
b = "B"
selectByUsedRows (a, b)
End Sub

评论中的正确代码,谢谢!

Sub selectByUsedRows(usedCol As String, selectCol As String)
n = Range(usedCol & "1").End(xlDown).Row
Range(selectCol & "1:" & selectCol & n).Select
End Sub

Sub Test1()
Dim a As String, b As String
a = "A"
b = "B"
selectByUsedRows a, b
End Sub

1 个答案:

答案 0 :(得分:3)

您正在调用selectByUsedRows,就像调用函数一样。调用子例程时不需要括号:

selectByUsedRows a, b