在MS excel表格中创建公式以从行和列

时间:2016-01-25 15:43:34

标签: excel

我有一张包含一些数据的表格。每天我们都要从中获取价值。 [C3] [D3] [I1]是我们接收数据的示例。字符是列,数字是行,因此我们必须手动匹配所需的值并提供输出。 你可以帮我创建一个公式,这样我就可以粘贴" [C1] [B3] [E2]" - 单元格中的此格式,并在任何其他单元格中接收输出。  我附上了一个快照供参考

Snap

2 个答案:

答案 0 :(得分:1)

以下公式使用FIND查找参考单元格中每个方括号的相对位置,然后您可以使用LEFTRIGHT返回每个方括号的内容对。最后,它使用INDIRECT使Excel将文本字符串作为单元格引用读取。

=INDIRECT(LEFT(RIGHT(H1,LEN(H1)-FIND("[",H1)),FIND("]",H1)-FIND("[",H1)-1))

=INDIRECT(LEFT(RIGHT(H1,LEN(H1)-FIND("[",H1,FIND("]",H1))),FIND("]",H1,FIND("[",H1,FIND("]",H1)))-FIND("[",H1,FIND("]",H1))-1))

=INDIRECT(LEFT(RIGHT(H1,LEN(H1)-FIND("[",H1,FIND("]",H1,FIND("[",H1,FIND("]",H1))))),FIND("]",H1,FIND("[",H1,FIND("]",H1,FIND("[",H1,FIND("]",H1)))))-FIND("[",H1,FIND("]",H1,FIND("[",H1,FIND("]",H1))))-1))

您可以使用&符号将结果连接到一个单元格中,如下所示:

=INDIRECT(LEFT(RIGHT(H1,LEN(H1)-FIND("[",H1)),FIND("]",H1)-FIND("[",H1)-1))&INDIRECT(LEFT(RIGHT(H1,LEN(H1)-FIND("[",H1,FIND("]",H1))),FIND("]",H1,FIND("[",H1,FIND("]",H1)))-FIND("[",H1,FIND("]",H1))-1))&INDIRECT(LEFT(RIGHT(H1,LEN(H1)-FIND("[",H1,FIND("]",H1,FIND("[",H1,FIND("]",H1))))),FIND("]",H1,FIND("[",H1,FIND("]",H1,FIND("[",H1,FIND("]",H1)))))-FIND("[",H1,FIND("]",H1,FIND("[",H1,FIND("]",H1))))-1))

修改

可能更容易使用SUBSTITUTE可视化Excel正在执行的操作,您可以在其中指定要关注的特定字符的实例。在下面的公式中,我们用特定的左右方括号替换我们的FIND公式的波形符号来查找,然后引用两者之间的子串。

=MID(H1,FIND("~",SUBSTITUTE(H1,"[","~",1))+1,FIND("~",SUBSTITUTE(H1,"]","~",1))-FIND("~",SUBSTITUTE(H1,"[","~",1))-1)

这样,为了找到第二个,第三个 n 的单元格引用,我们只增加实例编号:

=MID(H1,FIND("~",SUBSTITUTE(H1,"[","~",2))+1,FIND("~",SUBSTITUTE(H1,"]","~",2))-FIND("~",SUBSTITUTE(H1,"[","~",2))-1)

=MID(H1,FIND("~",SUBSTITUTE(H1,"[","~",3))+1,FIND("~",SUBSTITUTE(H1,"]","~",3))-FIND("~",SUBSTITUTE(H1,"[","~",3))-1)

再次,您可以在INDIRECT中包装其中的每一个,然后与&连接:

=INDIRECT(MID(H1,FIND("~",SUBSTITUTE(H1,"[","~",1))+1,FIND("~",SUBSTITUTE(H1,"]","~",1))-FIND("~",SUBSTITUTE(H1,"[","~",1))-1))&INDIRECT(MID(H1,FIND("~",SUBSTITUTE(H1,"[","~",2))+1,FIND("~",SUBSTITUTE(H1,"]","~",2))-FIND("~",SUBSTITUTE(H1,"[","~",2))-1))&INDIRECT(MID(H1,FIND("~",SUBSTITUTE(H1,"[","~",3))+1,FIND("~",SUBSTITUTE(H1,"]","~",3))-FIND("~",SUBSTITUTE(H1,"[","~",3))-1))

它不比第一个公式短(现在),但它可能更容易理解逻辑。更重要的是,扩展此版本以包含其他单元格引用要容易得多,例如,如果H1包含" [A1] [B12] [D32] [E4] [F19]"您只需连接整个INDIRECT公式的几个副本,并为每个公式增加实例编号。

答案 1 :(得分:1)

如果vba适合你,那么这个快速UDF将会这样做:

Either

将它放在工作簿附带的模块中:

enter image description here

然后您只需将其用作任何其他公式:

Function CONCATENATESPECIAL(rng As Range) As string
    Dim spArr() As String
    Dim i As Integer
    Dim temp As String
    temp = Replace(rng, "[", "")
    temp = Replace(temp, "]", "")
    spArr = Split(temp)
    For i = LBound(spArr) To UBound(spArr)
        CONCATENATESPECIAL = CONCATENATESPECIAL & Range(spArr(i))
    Next i
End Function

这将返回一个字符串。如果你想把它变成一个数字,那么:

=CONCATENATESPECIAL(H1)