我的问题:
我想遍历一个范围,并且每当它找到一个重复的值时,它应该从具有偏移量的单元格中获取该数量,并将其添加到第一个Cells数量的值。我有一个宏,可以确定它是否找到重复,但如果它有几个重复,那么我希望它重做任务,但只是继续找到重复项并加起来:)
到目前为止我有什么:
Sub LoopThroughRangeAndFindDuplicates ()
NumberOne = sht.Range("1:1").Find("Bilagsnr.").Address(False, False, xlA1)
Number = Application.WorksheetFunction.Substitute(FindNo, 1, "")
rng1 = NumberOne & ":" & Number & LastRow
No1Off = sht.Range(NumberOne).Offset(1, 0).Address(False, False, xlA1)
For Each c In sht.Range(rng1).Cells
rngOff1 = No1Off & ":" & Number & LastRow + 1
With Wf
n = .CountIfs(Range(rngOff1), c)
If n > 0 Then
CDuplicate = sht.Range(rngOff1).Find(c).Address(False, False, xlA1)
CDuplicateSub = Application.WorksheetFunction.Substitute(CDuplicate, Number, Amount)
CDuplicateSubValue = sht.Range(CDuplicateSub).Value
CValue = c.Address(False, False, xlA1)
CValueSub = Application.WorksheetFunction.Substitute(CValue, Number, Amount)
CValueSubValue = sht.Range(CValueSub).Value
sht.Range(CValueSub).Value = CValueSubValue + CDuplicateSubValue
End If
End With
No1Off = sht.Range(No1Off).Offset(1, 0).Address(False, False, xlA1)
Next c
目标:
如上所述,我希望宏重做If n > 0 Then
,如果它有比x多的重复项。在继续之前,我应该如何编写代码,让它查找多个重复项并添加它们,而不会使For Each
字符串真的很长? :)