本帖最后由 周某人就是我 于 2024-1-17 12:24 编辑
Sub Action()
Dim reg As Object
Dim mat As Object
Dim arr, arr1, arr2
Dim i%, n%, j%
Set reg = Create Object("vbscript.regexp")
arr = Range("A3:I252").Value2
arr1 = Array("A", "B", "C", "D", "E", "F")
arr2 = Array("字符1", "字符2", "字符3", "字符4", "字符5", "字符6")
Application.ScreenUpdating = False
i = 1
Do While arr(i, 6)) <> ""
Select Case arr(i, 6)
Case Is > 2
arr(i, 7) = "文本1"
Case Is > 0
arr(i, 7) = "文本2"
End Select
If InStr(8, arr(i + 1, 4), "C", 0) > 0 Then
Select Case arr(i + 1, 7)
Case Is = "文本3", "文本4"
arr(i + 1, 9) = "文本5"
End Select
ElseIf InStr(8, arr(i + 1, 4), "D", 0) > 0 Then
Select Case arr(i + 1, 7)
Case Is = "文本3", "文本4"
arr(i + 1, 9) = "文本6"
End Select
End If
If InStr(14, arr(i + 2, 4), "-1", 0) > 0 Then
If Len(arr(i + 3, 4)) < 14 Then
Select Case Len(arr(i + 4, 4))
Case Is > 14
arr(i + 3, 4) = Replace(arr(i + 2, 4), "-1", "-2")
Case Is < 14
arr(i + 3, 4) = Replace(arr(i + 2, 4), "-1", "-2")
arr(i + 4, 4) = Replace(arr(i + 2, 4), "-1", "-3")
End Select
End If
ElseIf InStr(14, arr(i + 2, 4), "-2", 0) > 0 Then
Select Case Len(arr(i + 3, 4))
Case Is < 14
arr(i + 3, 4) = Replace(arr(i + 2, 4), "-2", "-3")
End Select
ElseIf InStr(14, arr(i + 2, 4), "-3", 0) > 0 Then
If Len(arr(i + 3, 4)) < 14 Then
Select Case Len(arr(i + 4, 4))
Case Is > 14
arr(i + 3, 4) = Replace(arr(i + 2, 4), "-3", "-2")
Case Is < 14
arr(i + 3, 4) = Replace(arr(i + 2, 4), "-3", "-2")
arr(i + 4, 4) = Replace(arr(i + 2, 4), "-3", "-1")
End Select
End If
End If
If InStr(14, arr(i + 3, 4), "-1", 0) > 0 And Len(arr(i + 4, 4)) < 14 Then
arr(i + 4, 4) = Replace(arr(i + 3, 4), "-1", "-2")
ElseIf InStr(14, arr(i + 3, 4), "-2", 0) > 0 And Len(arr(i + 4, 4)) < 14 Then
arr(i + 4, 4) = Replace(arr(i + 3, 4), "-2", "-3")
ElseIf InStr(14, arr(i + 3, 4), "-3", 0) > 0 And Len(arr(i + 4, 4)) < 14 Then
arr(i + 4, 4) = Replace(arr(i + 3, 4), "-3", "-2")
End If
i = i + 5
Loop
For i = 1 to UBound(arr)
If arr(i, 6) = "" Then Exit For
arr(i, 1) = Date
If arr(i, 7) = "" Then
arr(i, 7) = "文本7"
End If
With reg
.Global =True
.Pattern ="\*\d{1,2}"
Set mat = .Execute(arr(i, 9))
If mat.Count > 0 Then
For n = 0 To mat.Count - 1
arr(i, 9) = .Replace(arr(i, 9), mat(n) & "MM")
Next
End If
For j = 0 to UBound(arr1)
.Pattern =arr1(j)
If .test(arr(i, 9)) Then
arr(i, 9) = .Replace(arr(i, 9), arr2(j))
End If
Next
End With
Next
Set reg = Nothing
Set mat = Nothing
Application.ScreenUpdating = True
Range("A3:I252").Value2 = arr
End Sub
|