这可以通过循环 VBA 中的行来完成,从列 A 和 B 中删除所有旧数据,然后使用一些字符串操作从列 C 和 D 中添加数据。这样的事情应该可以帮助您开始:
Sub sAddData()
On Error GoTo E_Handle
Dim ws As Worksheet
Dim lngLastRow As Long
Dim lngLoop1 As Long
Dim lngLoop2 As Long
Dim aInData() As String
Dim aOutData() As String
Dim strData As String
Set ws = Worksheets("Sheet4")
lngLastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
For lngLoop1 = 2 To lngLastRow
' deal with adding info from column D to column A
aOutData() = Split(ws.Cells(lngLoop1, 1), ";")
strData = ""
For lngLoop2 = LBound(aOutData) To UBound(aOutData)
If Left(aOutData(lngLoop2), 3) <> "ADD" Then strData = strData & aOutData(lngLoop2) & ";"
Next lngLoop2
aInData() = Split(ws.Cells(lngLoop1, 4), ";")
For lngLoop2 = LBound(aInData) To UBound(aInData)
Select Case Left(aInData(lngLoop2), 4)
Case "{S1}", "{S6}", "{S10"
strData = strData & Mid(aInData(lngLoop2), InStr(aInData(lngLoop2), "}") + 1) & ";"
End Select
Next lngLoop2
If Right(strData, 1) = ";" Then strData = Left(strData, Len(strData) - 1)
ws.Cells(lngLoop1, 1) = strData
' deal with adding info from column C to column B
strData = ""
strData = ws.Cells(lngLoop1, 2)
If Left(strData, 4) = "[NUM" Then strData = Mid(strData, InStr(strData, ".") + 2)
If Len(ws.Cells(lngLoop1, 3)) > 0 Then
strData = "[NUM - " & Replace(ws.Cells(lngLoop1, 3), "*", ", ") & "]. " & strData
End If
ws.Cells(lngLoop1, 2) = strData
Next lngLoop1
sExit:
On Error Resume Next
Exit Sub
E_Handle:
MsgBox Err.Description & vbCrLf & vbCrLf & "sAddData", vbOKOnly + vbCritical, "Error: " & Err.Number
Resume sExit
End Sub
问候,