的数据
目的是找到列c中的值与从更新的“firstvalue”变量获得的所有值之间的循环,这些值以逗号分隔并存储在列“M”中。
Sub circular()
Dim rng As Range, rng2 As Range, firstvalue As String, secondvalue As String
Set sh = ThisWorkbook.Worksheets("Sheet1")
lr = sh.Range("C" & Rows.Count).End(xlUp).Row
For Each rng In sh.Range("C5:C" & lr) 'iterating over each cell in column "c" from C5 till lastrow "lr".
firstvalue = rng.Offset(0, 10).value 'Corresponding cell value which is comma separated in column
"M" i:e after 10 columns from "C".
Dim n As Variant
For Each n In Split(firstvalue, ",") 'Looping through each value obtained from split function.
Set rng2 = sh.Range("C5:C" & lr).Find(Trim(n), LookIn:=xlValues) 'Finding that split value again
in column "C".
If Not rng2 Is Nothing Then 'if exists in column c then get.
secondvalue = rng2.Offset(0, 10).value 'corresponding cell values.
firstvalue = firstvalue & "," & secondvalue 'now first value is concatenated
with initial firstvalue
End If
Next n
MsgBox firstvalue
'Now I want to iterate over updated "firstvalue" in split function and this goes on in circular
fashion until rng value exists in firstvalue.
Next rng 'then change next rng and continue the above whole process for this value and so on.
End Sub
字符串
这段代码是为初始的第一个值工作,可以任何一个建议任何方法来覆盖更新的第一个值。
1条答案
按热度按时间aiazj4mn1#
我不确定我是否完全理解了你的目标,但是这段代码应该可以找到每个任务的所有precedent:
字符串