請參閱下面的代碼。它可能並不完美,但它是基於OP中的數據樣本進行工作的。它基於chr(34)
,這是"
的代碼。
Sub RepStr()
Dim lastrow As Long
Dim srchList As Worksheet
Dim mainList As Worksheet
Dim sStart As Long
Dim sStop As Long
Dim sValue As String
Dim pStart As Long
Dim pSttop As Long
Dim pValue As String
Set srchList = Sheets("Sheet8") '<- Sn Pn list
Set mainList = Sheets("Sheet7") '<- String List
lastrowMain = mainList.Range("A" & Rows.Count).End(xlUp).Row
lastrowsrch = srchList.Range("A" & Rows.Count).End(xlUp).Row
i = 1
While i <= lastrowMain
'Code based on your string is located at Column A of mainList
sStart = InStr(5, mainList.Range("A" & i).Value, Chr(34)) + 1
sStop = InStr(sStart + 1, mainList.Range("A" & i).Value, Chr(34))
sValue = Mid(mainList.Range("A" & i).Value, sStart, sStop - sStart)
pStart = InStr(InStr(1, mainList.Range("A" & i).Value, "PI"), mainList.Range("A" & i).Value, Chr(34)) + 1
pStop = InStr(pStart + 1, mainList.Range("A" & i).Value, Chr(34))
pValue = Mid(mainList.Range("A" & i).Value, pStart, pStop - pStart)
'Code based on your matching values are located at srchList Column A (S values), Column B (P values)
For j = 1 To lastrowsrch
If srchList.Range("A" & j).Value = sValue And srchList.Range("B" & j).Value = pValue Then
mainList.Range("A" & i).Value = Replace(mainList.Range("A" & i).Value, 0.7, 0.5)
End If
Next j
i = i + 1
Wend
End Sub
你好,我們坐在那裏每個字符集之間有1個空格嗎?我的意思是,例如,在「W2」和「S4」1空間之間以及在PF22和0.7 1空間之間。那是對的嗎? – Dubison 2015-02-24 16:52:22
並且對於Pn和Sn,n可以大於9嗎?它可以是2位數字嗎? – Dubison 2015-02-24 16:53:28
歡迎來到SO。請查看[如何提問](http://stackoverflow.com/help/how-to-ask),併發布您修改的代碼,以及您遇到的具體問題。 – guitarthrower 2015-02-24 16:58:34