我有一個包含幾千行的數據集,我正在搜索字符串中特定文本的每一行:7-16,7-26,7-36,13414 ,SHIPP,CONTAI等等。 (其中更多顯示如下)。InStr - 只在字符串的第一部分看看
問題是,有時某些零件編號在零件的末尾有「# - ##」,而不是在開頭,因此宏在將它分類爲「Container/PGSE Part/Trainers」時也會將其分類真的不是。
所以我正在尋找只會查看單元格中字符串的前4個字符的語法(僅適用於包含部件號而不是單詞的字符串)。
例如:
如果分別來看看含有「7-26 734372-102」我會希望它歸類爲一個「容器/ PGSE零件/培訓師」在細胞列51
如果分別來看看含有細胞「MS3520 7-26 3」我不會希望它在列51它歸類爲一個「容器/ PGSE零件/培訓師」,因爲它是在字符串的末尾。
Sub PGSE_Container_Trainer()
Dim rw As Integer
Set sht = ActiveWorkbook.ActiveSheet
rw = 2
Do Until sht.Cells(rw, 1) = ""
If InStr(1, Cells(rw, 8).Value, "7-16") Then
sht.Cells(rw, 51) = "Container/PGSE Part/Trainers"
GoTo LoopSkip
ElseIf InStr(1, Cells(rw, 8).Value, "7-26") Then
sht.Cells(rw, 51) = "Container/PGSE Part/Trainers"
GoTo LoopSkip
ElseIf InStr(1, Cells(rw, 8).Value, "7-36") Then
sht.Cells(rw, 51) = "Container/PGSE Part/Trainers"
GoTo LoopSkip
ElseIf InStr(1, Cells(rw, 8).Value, "7-46") Then
sht.Cells(rw, 51) = "Container/PGSE Part/Trainers"
GoTo LoopSkip
ElseIf InStr(1, Cells(rw, 8).Value, "7-56") Then
sht.Cells(rw, 51) = "Container/PGSE Part/Trainers"
GoTo LoopSkip
ElseIf InStr(1, Cells(rw, 8).Value, "7-66") Then
sht.Cells(rw, 51) = "Container/PGSE Part/Trainers"
GoTo LoopSkip
ElseIf InStr(1, Cells(rw, 8).Value, "7-76") Then
sht.Cells(rw, 51) = "Container/PGSE Part/Trainers"
GoTo LoopSkip
ElseIf InStr(1, Cells(rw, 8).Value, "7-86") Then
sht.Cells(rw, 51) = "Container/PGSE Part/Trainers"
GoTo LoopSkip
ElseIf InStr(1, Cells(rw, 8).Value, "7-96") Then
sht.Cells(rw, 51) = "Container/PGSE Part/Trainers"
GoTo LoopSkip
ElseIf InStr(1, Cells(rw, 8).Value, "13414") Then
sht.Cells(rw, 51) = "Container/PGSE Part/Trainers"
GoTo LoopSkip
ElseIf InStr(1, Cells(rw, 9).Value, "CONTAI") Then
sht.Cells(rw, 51) = "Container/PGSE Part/Trainers"
GoTo LoopSkip
ElseIf InStr(1, Cells(rw, 9).Value, "CNTNR") Then
sht.Cells(rw, 51) = "Container/PGSE Part/Trainers"
GoTo LoopSkip
ElseIf InStr(1, Cells(rw, 9).Value, "SHIPP") Then
sht.Cells(rw, 51) = "Container/PGSE Part/Trainers"
GoTo LoopSkip
ElseIf InStr(1, Cells(rw, 8).Value, "REN") Then
sht.Cells(rw, 51) = "Container/PGSE Part/Trainers"
GoTo LoopSkip
End If
LoopSkip:
rw = rw + 1
Loop
End Sub
使用左功能。 –
使用條件'如果InStr(1,Cells(rw,8).Value,「7-16」)= 1 Then'。這將檢查「7-16」是否在開頭。 –