2015-04-02 97 views
-2

細胞值的總和我有一個單一的細胞內的Excel工作表有很多的值如下:發現在也包含其他文本

a=5 
b=10 
c=44 
d=33 
... 

我想提取到的值的總和每個=之後。

我們該怎麼做?

+2

需要更多信息。所有的字符串都是精確的形式:「text1 =#1,text2 =#2,text3 =#3,...」,其中#n是整數? – 2015-04-02 17:55:06

回答

2

試一下這個小用戶自定義功能UDF

Public Function SumInCell(s As String) As Double 
    Dim s2 As String, d As Variant 
    s2 = s & "," 
    ary = Split(s2, "=") 

    SumInCell = 0 
    For i = LBound(ary) + 1 To UBound(ary) 
     s2 = ary(i) 
     d = CDbl(Mid(s2, 1, InStr(1, s2, ",") - 1)) 
     SumInCell = SumInCell + d 
    Next i 
End Function 

例如:

enter image description here

用戶定義函數(UDF)是非常容易安裝和使用:

  1. ALT-F11帶來了VBE窗口
  2. ALT-I ALT + M打開一個新的模塊
  3. 粘貼東西在和關閉窗口VBE

如果保存工作簿,UDF將隨之保存。 如果您正在使用一個版本的Excel更高然後2003,你必須保存 該文件作爲.XLSM而非的.xlsx

要刪除UDF:

  1. 彈出窗口VBE如上
  2. 清晰的代碼進行
  3. 關閉VBE窗口

從Excel使用UDF:

= SumInCell(A1)

要了解更多關於一般的宏,請參閱:

http://www.mvps.org/dmcritchie/excel/getstarted.htm

http://msdn.microsoft.com/en-us/library/ee814735(v=office.14).aspx

以及有關UDF的細節,請參見:

http://www.cpearson.com/excel/WritingFunctionsInVBA.aspx

必須啓用宏才能使其工作!

2

假設佈局如圖ColumnA,複製ColumnA到ColumnB,申請文本對ColumnB柱的=作爲分隔符,然後在C5:

=SUM(C1:C4) 

SO29419251 example

+0

謝謝,但我不想將它分成列,我想保留單個單元格,因爲它是非常巨大的,然後我需要一個非常長的公式來總和所有的值,我需要一些總和當它們仍然在該單個單元格內時的值。 – 2015-04-02 19:00:37

+0

如果我假定並顯示的佈局不是您所擁有的佈局,那麼可能值得您更清楚地瞭解您的佈局 - 無論如何回答@XOR LX的澄清要求。 – pnuts 2015-04-02 20:29:33

1

的公式答案,你需要做的是在2個單元所以你不要打的Excel

如果你的價值是在A1的嵌套的限制,

在B1把

=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(UPPER(SUBSTITUTE(A1,"=","'")),"A",""),"B",""),"C",""),"D",""),"E",""),"F",""),"G",""),"H",""),"I",""),"J",""),"K",""),"L",""),"M",""),"N",""),"O",""),"P",""),"Q",""),"R",""),"S",""),"T",""),"U",""),"V",""),"W",""),"X",""),"Y",""),"Z","")," ","")&"," 

在C1把

=SUMPRODUCT(MID(B1,FIND("@",SUBSTITUTE(B1,"'","@",ROW(INDIRECT("1:"&LEN(B1)-LEN(SUBSTITUTE(B1,"'",""))))))+1,FIND("*",SUBSTITUTE(B1,",","*",ROW(INDIRECT("1:"&LEN(B1)-LEN(SUBSTITUTE(B1,",",""))))))-(FIND("@",SUBSTITUTE(B1,"'","@",ROW(INDIRECT("1:"&LEN(B1)-LEN(SUBSTITUTE(B1,"'",""))))))+1))+0) 

這需要一段時間才能解決:)

相關問題