简体   繁体   English

如何在输入仅为一个单元格的Excel中创建多单元格数组公式?

[英]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.

相关问题 Excel:使用多单元格数组公式将函数应用于一系列范围 - Excel: Applying functions to a range of ranges using multi-cell array-formula Excel - 找到最高的多单元格总数 - Excel - Find highest MULTI-cell Total 需要帮助将多单元Excel公式转换为基本伪代码 - Need help converting a Multi-Cell Excel formula to basic pseudo code 如何为“如果一个单元格中的值为 1 然后乘以 1 等等”创建一个公式? - How do I create a formula for "if value in one cell is 1 then multiply by 1 and so on? 如何将字体和内部颜色从一个多单元格范围复制到另一个? - How to copy font and interior color from one multi-cell range to another? 如何检查多单元格范围是否包含任何错误? - How can I check if a Multi-Cell Range contains any errors? VBA UDF 多单元参考 - VBA UDF multi-cell reference Excel - 将包含数组公式的单元格作为输入传递给另一个单元格中的函数 - Excel - Passing a cell containing an array formula as input to a function in another cell 如何在excel中创建一个公式来搜索行中的值,然后从该列中的另一个单元格中获取值? - How do I create a formula in excel that searches for a value in row, and then takes the value from another cell in that column? 如何创建 Power Query 自定义列并将 excel 公式插入到最终表格的每个单元格中? - How do i create a Power Query custom column AND insert an excel formula into each cell of the final table?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM