请参阅下面的代码。它可能并不完美,但它是基于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