合并Excel中的行并与OR分开

时间:2017-06-27 22:51:01

标签: excel vba excel-vba

在工作中,我会定期获得Excel工作表,其中包含一列数字(可以是4到12位数字的任意长度)。有时我会得到一些,有时我会得到数百。我需要使用Windows资源管理器(它是基于SMB的服务器)在Isilon服务器中搜索这些数字,它一次可以处理大约50个数字。

现在唯一能做到这一点的方法是老式的方法 - 我从Excel中的数字列中复制50个数字并将其粘贴到记事本中。然后我将所有数字都排成一行并手动粘贴每个数字之间的OR函数。所以我最终得到这样的东西(这只有10个,但最多可能达到50个):

1266135 OR 1266197 OR 1266197 OR 1266197 OR 1266256 OR 1266256 OR 1266256 OR 1266418 OR 1266418 OR 1266418

我对VBA不太好,我主要依赖于我可以用宏做什么。在Windows中自动格式化一列数字看起来像这样在我之外。我已经尝试了我在Stack上找到的一些东西,但到目前为止最困难的部分是在每个数字之间放置OR函数。

有关从哪里开始的任何建议?谢谢你的帮助!

2 个答案:

答案 0 :(得分:0)

与其他评论者一样,我会推荐一个能够自动生成所需文本(递归)或宏的函数。但是,如果你喜欢某些东西,你可以粘贴到一个单元格中以获得你想要的东西,它看起来就像

=CONCATENATE(A1," OR ",A2," OR ",A3," OR ",A4," OR ",A5," OR ",A6," OR ",A7," OR ",A8," OR ",A9," OR ",A10," OR ",A11," OR ",A12," OR ",A13," OR ",A14," OR ",A15," OR ",A16," OR ",A17," OR ",A18," OR ",A19," OR ",A20," OR ",A21," OR ",A22," OR ",A23," OR ",A24," OR ",A25," OR ",A26," OR ",A27," OR ",A28," OR ",A29," OR ",A30," OR ",A31," OR ",A32," OR ",A33," OR ",A34," OR ",A35," OR ",A36," OR ",A37," OR ",A38," OR ",A39," OR ",A40," OR ",A41," OR ",A42," OR ",A43," OR ",A44," OR ",A45," OR ",A46," OR ",A47," OR ",A48," OR ",A49, " OR ", A50)

(很长时间为50) 一旦你完成了一次,你可以通过向下拖动一个单元格(增加所有数字)或替换" A"来获取你需要的任何单元格。通过向左/向右拖动另一个单元格(只需将起始单元格偏移到您想要的任何位置)。此单元格的输出是从公式中第一个列出的单元格开始直接向下的一组50。这可能是最拖放的'获得你想要的文字的方法。

答案 1 :(得分:0)

这是一个VBA版本,它连接Sheet1

上A列的所有值
temp = temp->next

输出:Public Sub MergeVals() Debug.Print Join(Application.Transpose(Sheet1.UsedRange.Columns(1)), " Or ") End Sub