[英]How do I create a multi-cell array formula in Excel whose input is just one cell?
I have a cell with a spaced delimited string say "NULL 9" 我有一个以空格分隔的字符串表示“ NULL 9”的单元格
Say this data is stored in A1. 假设此数据存储在A1中。
I have a function called 我有一个叫做
Function splitCell(str As String) As String()
splitCell = split(str, " ")
End Function
I am trying to break the cell into a string array, what I then want to do is to have a formula such as 我正在尝试将单元格拆分为字符串数组,然后要做的是使用一个公式,例如
{=splitCell(A1)}
at the locations A2 and A3, so that A2 would contain "NULL" and A3 would contain "9". 在位置A2和A3上,因此A2将包含“ NULL”,而A3将包含“ 9”。 Where am I going wrong?
我要去哪里错了? Please help.
请帮忙。 Thanks
谢谢
You need to assign the result of the Split to a variant, and if you want the result to be vertical rather horizontal you need to transpose it. 您需要将Split的结果分配给一个变量,并且如果您希望结果是垂直而不是水平的,则需要对其进行转置。
Public Function SplitCell(rng As Range) As Variant
SplitCell = Application.Transpose(Split(rng))
End Function
You can do this entirely with Excel formulas: 您可以使用Excel公式完全做到这一点:
A2: =LEFT(A1,FIND(" ",A1))
A3: =MID(A1,FIND(" ",A2)+1,LEN(A1)-FIND(" ",A2))
This should give you the result you are after. 这应该给您您想要的结果。
Sorry, missed that you wanted to expand beyond the simple version. 抱歉,错过了您想要扩展到简单版本以外的地方。
Function splitCell(str As String, pos As Integer) As String
Dim strarray() As String
strarray = Split(str, " ")
splitCell = strarray(pos)
End Function
A2: =splitCell(A1,0)
You will need to put the function into a module (not in the sheet code) 您需要将函数放入模块中(不在工作表代码中)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.