|
楼主 |
发表于 2023-2-22 15:28
|
显示全部楼层
Sub 化验整理()
Dim reg As Object
Set reg = CreateObject("vbscript.regexp")
Dim sr, x
For x = 1 To Range("a65536").End(xlUp).Row
sr = Cells(x, 1)
With reg
.Global = True
.IgnoreCase = True
.Pattern = "(天|丰)"
For Each Item In .Execute(sr)
ss = ss & Item
Next
Cells(x + 1, 3) = ss
End With
ss = ""
Next x
'=======================================================
Set reg = CreateObject("vbscript.regexp")
For x = 1 To Range("a65536").End(xlUp).Row
sr = Cells(x, 1)
With reg
.Global = True
.IgnoreCase = True
.Pattern = " (.*)(?=样)"
For Each Item In .Execute(sr)
ss = ss & Item
Next
Cells(x + 1, 3) = ss
End With
ss = ""
Next x
'=======================================================
Set reg = CreateObject("vbscript.regexp")
For x = 1 To Range("a65536").End(xlUp).Row
sr = Cells(x, 1)
With reg
.Global = True
.IgnoreCase = True
.Pattern = "\d+月\d+(号|日)"
For Each Item In .Execute(sr)
ss = ss & Item
Next
Cells(x + 1, 2) = ss
End With
ss = ""
Next x
'==========================================================
a = Array("低位") ', "水分:", "空干基挥发:", "硫:")
For i = 2 To 10
For Each aa In a '遍历字符
k = InStr(Cells(i, 1), aa) '如果包含字符,那么k的值大于0,否则等于0
If k > 0 Then
kk = Len(aa) + k '//返回第一个数字的位置
Cells(i, 5) = Val(Mid(Cells(i, 1), kk, 99)) '读取数字
End If
Next
Next
a = Array("水分:") ', "空干基挥发:", "硫:")
For i = 2 To 10
For Each aa In a '遍历字符
k = InStr(Cells(i, 1), aa) '如果包含字符,那么k的值大于0,否则等于0
If k > 0 Then
kk = Len(aa) + k '//返回第一个数字的位置
Cells(i, 6) = Val(Mid(Cells(i, 1), kk, 99)) '读取数字
End If
Next
Next
a = Array("硫:")
For i = 2 To 10
For Each aa In a '遍历字符
k = InStr(Cells(i, 1), aa) '如果包含字符,那么k的值大于0,否则等于0
If k > 0 Then
kk = Len(aa) + k '//返回第一个数字的位置
Cells(i, 7) = Val(Mid(Cells(i, 1), kk, 99)) '读取数字
End If
Next
Next
a = Array("空干基挥发:")
For i = 2 To 10
For Each aa In a '遍历字符
k = InStr(Cells(i, 1), aa) '如果包含字符,那么k的值大于0,否则等于0
If k > 0 Then
kk = Len(aa) + k '//返回第一个数字的位置
Cells(i, 8) = Val(Mid(Cells(i, 1), kk, 99)) '读取数字
End If
Next
Next
End Sub
拼凑成这样了,可以使用,哪位大师给整理一下 |
|