我想要的是查看循环后增加的cell.value是否等于其自身,但等于先例。
If Not Intersect(Target, rng) Is Nothing Then
risorsa = Cells(Target.ROW, 3).Value
For Each cell In rngCalendario
If UCase(cell.Value) Like "*" & risorsa & "*" Then '
For i = cell.ROW To RigaNomeProgetto Step -1
If Cells(i, 2).Value = 0 And cell.ROW < ultimaRiga Then
NomeProgetto = Cells(i, 1).Value
Exit For
End If
Next i
Output = LTrim(Output) & NomeProgetto & Chr(10) & Chr(10) & Chr(10)
End If
Next cell
Cells(2, 4) = Output
End if
答案 0 :(得分:2)
您在这里:
If Not Intersect(Target, rng) Is Nothing Then
Dim prevCell As Variant 'Choose applicable type, probably String
risorsa = Cells(Target.Row, 3).Value
For Each cell In rngCalendario
If UCase(cell.Value) Like "*" & risorsa & "*" And prevCell = cell.Value Then 'current cell value is compared to previous cell
For i = cell.Row To RigaNomeProgetto Step -1
If Cells(i, 2).Value = 0 And cell.Row < ultimaRiga Then
NomeProgetto = Cells(i, 1).Value
Exit For
End If
Next i
Output = LTrim(Output) & NomeProgetto & Chr(10) & Chr(10) & Chr(10)
End If
prevCell = cell.Value 'prevCell is assigned the value of the current cell
Next cell
Cells(2, 4) = Output
End If