如果列A - H的数据可能会或可能不会在每列中重复,我希望将列中的数据合并到一列并删除重复项。
这是可以使用FORMULA还是需要macro / vba?
我更喜欢公式,因为后者不是我的力量(不是第一个; - ))
答案 0 :(得分:2)
答案 1 :(得分:0)
在vba中尝试此宏,选择列然后按(Alt + F11)并在工作表的模块中粘贴此代码:
Sub MakeOneColumn()
Dim vaCells As Variant
Dim vOutput() As Variant
Dim i As Long, j As Long
Dim lRow As Long
If TypeName(Selection) = "Range" Then
If Selection.Count > 1 Then
If Selection.Count <= Selection.Parent.Rows.Count Then
vaCells = Selection.Value
ReDim vOutput(1 To UBound(vaCells, 1) * UBound(vaCells, 2), 1 To 1)
For j = LBound(vaCells, 2) To UBound(vaCells, 2)
For i = LBound(vaCells, 1) To UBound(vaCells, 1)
If Len(vaCells(i, j)) > 0 Then
lRow = lRow + 1
vOutput(lRow, 1) = vaCells(i, j)
End If
Next i
Next j
Selection.ClearContents
Selection.Cells(1).Resize(lRow).Value = vOutput
End If
End If
End If
End Sub
然后按F5执行宏。