简体   繁体   English

合并Excel中的行并用OR分隔

[英]Merge rows in Excel and separate with OR

At work I get Excel sheets pretty regularly that contain a column of numbers (which can be anywhere from 4 to 12 digits long). 在工作中,我会很定期地获得Excel工作表,其中包含一列数字(长度可以是4到12位数字)。 Sometimes I get a few, sometimes I get hundreds. 有时我得到一些,有时我得到数百。 I need to search for these numbers in an Isilon server using Windows Explorer (it is an SMB based server) which can handle roughly 50 numbers at a time. 我需要使用Windows资源管理器(它是基于SMB的服务器)在Isilon服务器中搜索这些数字,该服务器一次可以处理大约50个数字。

The only way to do this right now is the old fashioned way - I copy 50 numbers from the column of numbers in Excel and paste them into Notepad. 现在唯一的方法就是老式的方法-我从Excel中的数字列中复制50个数字并将其粘贴到记事本中。 I then make all of the numbers one row and manually paste in between each number the OR function. 然后,我将所有数字排成一行,然后手动在每个数字之间粘贴OR函数。 So I end up with something like this (this is only 10 but it could be up to 50): 所以我最终得到这样的结果(只有10个,但最多可能有50个):

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

I'm not that good with VBA, I rely mostly on what I can do with macros. 我对VBA不太满意,我主要依靠我可以对宏执行的操作。 Auto formatting a column of numbers to look like this for searching in Windows is beyond me. 自动格式化一列数字使其看起来像在Windows中进行搜索超出了我的范围。 I have tried some of the things I've found here on Stack but the hardest part so far has been to place the OR function between each number. 我已经尝试过一些我在Stack上找到的东西,但是到目前为止,最困难的部分是将OR函数放在每个数字之间。

Any suggestions on where to start? 关于从哪里开始的任何建议? Thanks for any help! 谢谢你的帮助!

In the same vein as one of the other commenters, I would recommend a function that would auto-generate the text you need for you (recursively) or a macro. 按照与其他评论者之一相同的方式,我推荐一个函数,该函数可以自动(递归)生成您需要的文本或宏。 However, if you'd like something you could just paste into a cell to get what you want, it would look something like 但是,如果您想要一些东西,可以将其粘贴到单元格中以获取所需的东西,则它看起来像

=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)

(pretty long for 50) Once you've done it once, you can take whatever cells you need by either dragging a cell with this formula down (to increment all the numbers) or replacing the "A" with another cell by dragging left/right (just offsetting the starting cell to whatever you want). (相当长,为50)一次完成后,您可以通过向下拖动具有该公式的单元格(增加所有数字)或通过向左/拖动“ A”替换另一个单元格来获取所需的任何单元格正确(只是将起始单元偏移到您想要的任何位置)。 The output of this cell is a set of 50 starting from the first listed cell in the formula and going straight down. 此单元格的输出是一组50,从公式中第一个列出的单元格开始一直向下。 This might be the most 'drag and drop' way to get the text you want. 这可能是获取所需文本的最“拖放”方式。

Here is a VBA version that joins all values from column A on Sheet1 这是一个VBA版本,它将Sheet1上A列的所有值连接在一起

Public Sub MergeVals()

    Debug.Print Join(Application.Transpose(Sheet1.UsedRange.Columns(1)), " Or ")

End Sub

Output: 1266135 Or 1266197 Or 1266197 Or 1266197 Or 1266256 Or 1266256 输出: 1266135 Or 1266197 Or 1266197 Or 1266197 Or 1266256 Or 1266256

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM