我编写了一个代码来搜索每个数组变量,如果存在于工作表的每一行中。现在,当找到匹配项时,我需要知道列号是什么,在哪里找到了搜索字符串。知道如何使用 vb 脚本来获得它吗?
ParentColmnCount=ParentColmnCount-1
IntRow6=2
DataCount=0
Do While objSheet6.Cells(IntRow6,1).Value <> ""
For DataCount=0 to UBound(VMHArray)
If Not objSheet6.Range(objSheet6.Cells(IntRow6,1),objSheet6.Cells(IntRow6,ParentColmnCount)).Find(VMHArray(DataCount)) Is Nothing Then
MsgBox(objSheet6.Range(objSheet6.Cells(IntRow6,1),objSheet6.Cells(IntRow6,ParentColmnCount)).Find(VMHArray(DataCount)).Columns)
End If
Next
IntRow6=IntRow6+1
Loop
更新:
IntRow6=2
DataCount=0
Do While objSheet6.Cells(IntRow6,1).Value <> ""
For DataCount=0 to UBound(VMHArray)
Set rSearch = objSheet6.Cells(IntRow6,1).EntireRow
Set rFound = rSearch.Find(VMHArray(DataCount))
If Not rFound Is Nothing Then
adrFirst = rFound.Address
Do
MsgBox(IntRow6)
MsgBox(rFound.Column + 1)
MsgBox(adrFirst)
rCol=rFound.Column
objSheet6.Cells(IntRow6,rCol + 2)= objSheet6.Cells(IntRow6,rCol + 5)
Set rFound = rSearch.FindNext(rFound)
Loop Until rFound.Address <> adrFirst And Not rFound Is Nothing
End If
Next
IntRow6=IntRow6+1
Loop
但似乎控件陷入了无限循环并不断给出 21 作为其第一个匹配的列号。产生如下输出:
2 33 $AF$2 2 33 $AF$2 2 33 $AF$2 .......
知道为什么吗?
谢谢