Excel 擅长。合并列并删除重复项

Excel 擅长。合并列并删除重复项,excel,merge,Excel,Merge,如果A-H列中的数据在每列中可能重复,也可能不重复,那么我希望将这些列中的数据合并到一列中,并删除重复项 这在公式中是可能的,还是需要宏/vba 我更喜欢公式,因为后者不是我的力(也不是第一个;-)在vba中尝试此宏,选择列,然后按(Alt+F11),然后在工作表的模块中粘贴此代码: Sub MakeOneColumn() Dim vaCells As Variant Dim vOutput() As Variant Dim i As Long, j As Long Dim lRow As L

如果A-H列中的数据在每列中可能重复,也可能不重复,那么我希望将这些列中的数据合并到一列中,并删除重复项

这在公式中是可能的,还是需要宏/vba


我更喜欢公式,因为后者不是我的力(也不是第一个;-)

在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
子MakeOneColumn()
变暗真空管
Dim vOutput()作为变量
我和我一样长,我和我一样长
暗淡的光线和长的一样
如果TypeName(选择)=“范围”,则
如果Selection.Count>1,则
如果选择。则计数为0
lRow=lRow+1
vOutput(lRow,1)=真空室(i,j)
如果结束
接下来我
下一个j
选择.ClearContents
Selection.Cells(1).调整大小(lRow).Value=vOutput
如果结束
如果结束
如果结束
端接头

然后按F5执行宏

在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
子MakeOneColumn()
变暗真空管
Dim vOutput()作为变量
我和我一样长,我和我一样长
暗淡的光线和长的一样
如果TypeName(选择)=“范围”,则
如果Selection.Count>1,则
如果选择。则计数为0
lRow=lRow+1
vOutput(lRow,1)=真空室(i,j)
如果结束
接下来我
下一个j
选择.ClearContents
Selection.Cells(1).调整大小(lRow).Value=vOutput
如果结束
如果结束
如果结束
端接头

然后按F5执行宏

Google Sheets通过以下公式实现这一点:

 =sort(unique({A:A;B:B}))


也许有一个Excel等价物?

Google Sheets通过以下公式实现这一点:

 =sort(unique({A:A;B:B}))


也许有一个Excel等价物?

将列复制到G工作表。输入公式。。happy camper=me..这里有一个关于Excel的建议,但要将更复杂的列复制到G.Sheets。输入公式。。happy camper=me.这里有一个关于Excel的建议,但要复杂得多