Sub Main()
With Columns(1).SpecialCells(xlCellTypeConstants, XlTextValues).Offset(,1).SpecialCells(xlCellTypeBlanks)
.FormulaR1C1 = "=R[-1]C"
.Value = .Value
End With
End Sub
哪里
第一个SpecialCells选择具有一些文本值的A列单元格
偏移量在右边的下一列中选择相应的单元格(即列B)
第二个SpecialCells选择后一个范围内的空单元格
2
一个起点是遍历每个值并将其与列中的每个值进行比较:
Sub FillDuplicates()
Dim lastrow As Long
lastrow = Cells(Rows.Count, "A").End(xlUp).Row 'find last row in column A
For x = 1 To lastrow
If Cells(x, 2).Value <> "" Then 'Check if cell in column B is empty
For y = 1 To lastrow
If Cells(y, 1).Value = Cells(x, 1).Value Then 'Compares cell against each value in column A
Cells(y, 2).Value = Cells(x, 2).Value 'If matches, add value in column B
End If
Next y
End If
Next x
End Sub
2 回答
你可以试试这个
哪里
第一个SpecialCells选择具有一些文本值的A列单元格
偏移量在右边的下一列中选择相应的单元格(即列B)
第二个SpecialCells选择后一个范围内的空单元格
一个起点是遍历每个值并将其与列中的每个值进行比较: