我的要求是这样的:
守则是:
For Each workSheet1 In MainWorkBook.Worksheets
Set MainWorksheet = workSheet1
Set SecondaryWorksheet = workSheet1
MainWorksheet.Activate
Cells.Select
Selection.EntireColumn.Hidden = False
Selection.EntireRow.Hidden = False
rowcount = MainWorksheet.Cells(Rows.count, 1).End(xlUp).Row
For i = 3 To rowcount
MainCheckName = Trim(MainWorksheet.Cells(i, "A"))
If (PreviousCheck <> MainCheckName And MainCheckName <> "") Then
SecondaryWorksheet.Activate
rowcount = SecondaryWorksheet.Cells(Rows.count, 1).End(xlUp).Row
SecondaryWorksheet.Range(SecondaryWorksheet.Cells(1, "A"), SecondaryWorksheet.Cells(rowcount, "A")).Select
Set SecondaryCheckName = Selection.Find(what:=MainCheckName, LookAt:=xlWhole)
If Not SecondaryCheckName Is Nothing Then
CheckRow = Selection.Find(what:=MainCheckName, LookAt:=xlWhole).Row
<further process here>
Next Next
现在,我对这一行有疑问:
Set SecondaryCheckName = Selection.Find(what:=MainCheckName, LookAt:=xlWhole)
将此活动处理了大约十张后,虽然我的内容在不同工作簿的两个工作表中都匹配,但我为Nothing
函数返回了Find
。
出了什么问题,为什么这里的情况失败了?
答案 0 :(得分:2)
您没有包含SecondaryCheckName
的声明,但是每个指示都是字符串而不是Range类型变量。您不应Set
将Range object更改为Range.Find method返回的angular-ui-bootstrap-tab;它应该简单地分配给.Find结果的值。或者,将其声明为Range类型变量,以便您可以Set
将其作为Range对象以供将来使用。
SecondaryCheckName = Selection.Find(what:=MainCheckName, LookAt:=xlWhole).Value2
那就是你收到错误的原因的答案。但是,我不认为这是实现目标的最佳方式。确定缺乏错误控制,如果不能完全避免使用,请减少。选择and
选择。