如何提取excel vba中search词后面的冒号后面的值

我在Excel中有一个单元格中的以下数据。 我需要编写一个VBA excelmacros从下面的数据中提取一些数据。

****************** AUDIT REPORT RUN STATISTICS*********** Environment : PROD Job Name : CLM_E_CLMHUB_GDWCLM_4017_D_MAIG Server Name : etlprod-grid.ent.rt.csaa.com Server IP Address : 172.26.137.11 Source Success Count ( s_m_extract_maig_req / V_GW_INT_CLS_MAIG ) : 691 Source Reject Count ( s_m_extract_maig_req / V_GW_INT_CLS_MAIG ) : 0 Target Success Count ( s_m_extract_maig_req / CLM_E_CLMHUB_GDWCLM_4017_D_MAIG.xml ) : 691 Target Reject Count ( s_m_extract_maig_req / CLM_E_CLMHUB_GDWCLM_4017_D_MAIG.xml ) : 0 SUMMARY Source Total Records : 691 Target Total Records : 691 ETL Start : 02/25/2015 21:30:00 ETL End : 02/25/2015 21:30:15 ETL Duration(HH:MI:SS) : 00 days 00:00:15 Business Day : 02/25/2015 21:30:16 Run Day : 2015-02-25T00:00:00-07:00 Status : JOB_ENDED_SUCCESSFULLY 

我需要通过search相同的文本并获取在下一个冒号后面和下一个新行之前的数字来获取Source Total Records的值(即691)是否有任何string函数可用于search任何字比如Source Total Records ),并find后面冒号(:)的位置,并将结果提取到冒号右侧。

如果我的问题很长或模糊,我很抱歉。 任何澄清需要是受欢迎的。

像这样的东西应该为你工作:

 Sub getSourceTotalRecords() target = "Source Total Records" inputData = Cells(1, 1) 'or wherever your text is dataLines = Split(inputData, vbNewLine) For Each l In dataLines If Left(l, Len(target)) = target Then colonLocation = InStr(l, ":") MsgBox Mid(l, colonLocation + 1) Exit For 'if you're not looking for multiple hits End If Next l End Sub 

这将MsgBox的值。 你可能想要改变它做一些别的事情。 如果你想检索其他数据,你也可以调整它以把target作为参数。

非VBA解决scheme(如果您的源文本在单元格A1 ):

 A2: =SEARCH(":",A1,SEARCH("Source Total Records",A1)) A3: =SEARCH(CHAR(10),A1,A2) A4: =VALUE(MID(A1,A2+2,A3-A2-2))