Excel - 连接多列 [英] Excel - Concatenate many columns

查看:30
本文介绍了Excel - 连接多列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Excel 中连接一堆列.我知道我可以手动执行:

I'm trying to concatenate a bunch of columns in Excel. I know I can manually do with:

=A1&", "&B1&", "&C1(依此类推)

但我有大约 40 列,我正在寻找一种方法来简化此过程.

but I have about 40 columns, and I'm looking for a way to streamline this process.

在此先感谢您的帮助!

推荐答案

作为一个用户函数,取一个 range

As a user function taking a range

Public Function ClarkeyCat(ByRef rng As Range) As Variant

Dim c As Range
Dim ans As Variant

For Each c In rng

If (c.Value <> "") Then
    ans = IIf(ans = "", "", ans & ",") & c.Value
End If

Next

ClarkeyCat = ans
End Function

改变Variant 类型,如果你需要的话(到string,很可能).

Changing the Variant types, if you need to (to string, most likely).

像这样使用:

这篇关于Excel - 连接多列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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