【发布时间】:2011-11-29 06:46:31
【问题描述】:
使用:Excel 2007/Win 7
首先,我创建了一个子程序来查找名为“WIP”的工作表的动态范围:
Sub GetWIPRange()
Dim WIPrng1 As Range
Dim WIPrng2 As Range
Sheets("WIP").Activate
Set WIPrng1 = Cells.find("*", [a1], , , xlByRows, xlPrevious)
Set WIPrng2 = Cells.find("*", [a1], , , xlByColumns, xlPrevious)
If Not WIPrng1 Is Nothing Then
Set WIPrng3 = Range([a1], Cells(WIPrng1.Row, WIPrng2.Column))
Application.Goto WIPrng3
Else
MsgBox "sheet is blank", vbCritical
End If
End Sub
现在我想在上面定义的范围内找到给定的合同编号:
Sub find()
Dim find As Long
find = Application.WorksheetFunction.Match("545499", Range(WIPrng3.Parent.Name & "!" & WIPrng3.Address), 0)
MsgBox "Found at row : " & find
End Sub
但是我从上面的代码中得到的错误是:
运行时错误“91”: 对象变量 未设置块变量。
- 如何修复此代码,使其返回我正在寻找的值的行号?
- 是否有使用 VBA 查找单元格值的更有效方法?例如,如果我有很多工作表,我想搜索所有工作表并返回一个值的特定行号和工作表位置。
非常感谢!
【问题讨论】:
标签: vba excel excel-2007