【发布时间】:2016-05-12 22:31:43
【问题描述】:
你好,如果有谁可以帮助解决这个问题
我有一组 1 到多个组(最多 12 行 - 每组一个后一行)字符串的初始部分重复我不知道它们重复的时间,但每次我需要它们提取重复字符串之后的所有相关数据。现在并非所有 12 行都在组中,有时有 11 行或更少,但它们在数据组中没有空白行,所以我所做的是一旦我找到我的标题行,我就会调用一个子程序来遍历数据块并执行我的提取,但是当我回来使用 .findnext(v) 时,它不会转到下一个标题
With big_rng ' this is column A selected
Set v = .Find("Submarket:", LookIn:=xlValues, LookAt:=xlPart)
If Not v Is Nothing Then
firstAddress = c.Row
Do
Call this1(need, c.Row, tech, daily_date)
Set v = .FindNext(v)
need = need + 1
Loop While Not c Is Nothing And c.Address <> firstAddress
End If
End With
当我调用 this1 时,我正在做的是选择另一个范围,因为我不知道我的数据是否按正确的顺序我使用另一个选择
Cells(i, 1).Select ' I know which row my group starts and I select down
Range(Selection, Selection.End(xlDown)).Select
' check for substrings and copy across if the substring exists e.g.
With Selection
Set d = .Find("Degradation =", LookIn:=xlValues, LookAt:=xlPart)
If Not d Is Nothing Then
spos = InStrRev(Cells(d.Row, 1), "=")
If Mid(Cells(d.Row, 1), spos + 1, 1) = " " Then
output_sht.Cells(n, 5) = Right(Cells(d.Row, 1), Len(Cells(d.Row, 1)) - (spos + 1))
Else
output_sht.Cells(n, 5) = Right(Cells(d.Row, 1), Len(Cells(d.Row, 1)) - spos)
End If
Else
output_sht.Cells(n, 5) = "Error in Data"
End If
当这个 Sub 结束时,我的原始选择消失了(它是 A:A 列),并且我的 .findnext(v) 给了我上一组的最后一行,而不是下一组的第一行(如果存在的话)
如何通过 findnext 循环,同时保持我原来的选择完好无损
提前谢谢你
罗伯特
【问题讨论】:
-
Excel 在使用
FINDNEXT时使用最后一个FIND值,因此它使用this1搜索中的值。我认为您将使用最后找到的项目作为起点将.FINDNEXT替换为另一个FIND,但保留 firstAddress 以便它知道何时回到起点。