【发布时间】:2018-04-12 15:39:29
【问题描述】:
我创建了一个宏,用另一张表中的特定数据填充缺失的数据,这些代码在从客户端的 excel 复制粘贴数据并准备开始工作所需的数据时完美工作,但下面唯一的问题是
代码:
With Worksheets("Feuil2")
' reference "target" sheet (change "Target" to our actual target sheet name)
With .Range("B1:B" & .Cells(.Rows.Count, 1).End(xlUp).Row) 'reference
its column B range from row 1 down to last not empty one
If WorksheetFunction.CountBlank(.Cells) > 0 Then
' if any blank cell in referenced range. this check to avoid error thrown by subsequent
statament
.SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=index(GDC!" & rng.Offset(, 1).Address(, , xlR1C1) & ",match(RC[-1],GDC!" & rng.Address(, , xlR1C1) & ",0))" 'fill blank cells with a lookup (well, sort of) formula
.Value = .Value 'get rid of formulas and leave values only
Cells.Select
End If
End With
End With
这段代码在匹配和填充数据方面工作得很好,但是当例如找到一个重复的值时,它只复制第一个值而不是第二个
请参阅下图以更好地了解主要问题:
正如您在图像中看到的那样,在 A 列中,我可能有数据重复两次,如该值 P20845,在 F 列中重复一个名称为 Ghaith,另一个名称为 sirine,但正如您可以在 A 列中看到它也只是 Ghaith 的名字,没有 sirine 的名字 任何想法或更好的解决方案来解决这个问题并获得所有需要的数据? .
最好的问候
波洛斯
【问题讨论】:
-
我已经多次阅读这个问题,但我仍然无法告诉 什么 您的确切问题是什么。你能再解释一下吗?
-
@dwirony 谢谢你的回答,在图像中有一个值
P20845 column A with the name of Gaith in front of it我想要的是当我运行我的代码并发现重复的值时,它会将结果都放在前面第一个数据和第二个像这样column B the value P20845 is repeated twice one with name of ghaith and one with the name of sirine所以有什么办法可以进入 A 列in front of P20845 something like this Ghiath/sirine查看图片