Excel VBA:找到两个表的联合 [英] Excel VBA: find the union of two tables

查看:193
本文介绍了Excel VBA:找到两个表的联合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 vba 的新功能,我有两个更新的文本和文本列我想找到两列的联合。

I am new to vba and I've got two updating columns of text & I want to find the union of the two columns.

例如

+---------+---------+
| ColumnA | ColumnB |
+---------+---------+
|   ABC   |    F    |
|   DE    |    F    |
|   F     |   AB    |
|   DBCA  |   CDE   |
|   E     |         |
+---------+---------+

我想将结果写入新列 columnC 订单无关紧要

I want to write the result in a new column columnC (order doesn't matter)

+---------+
| ColumnC |
+---------+
|   ABC   |
|   F     |
|   DE    |
|   DBCA  |
|   E     |
|   AB    |
|   CDE   |
+---------+

如何解决这个问题?谢谢。

How to work out this? Thanks.

推荐答案

编辑:添加删除重复的值

尝试这个

Sub main()
    With Worksheets("Columns") '<--| change "Columns" to your actual worksheet name
        With .Range("A1", .Range("A1").End(xlDown))
            .Parent.Range("C1").Resize(.Rows.Count).Value = .Value
        End With
        With .Range("B1", .Range("B1").End(xlDown))
            .Parent.Range("C1").End(xlDown).Offset(1).Resize(.Rows.Count).Value = .Value
        End With
        .Range("C1", .Range("C1").End(xlDown)).RemoveDuplicates Array(1)
    End With
End Sub

这篇关于Excel VBA:找到两个表的联合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆