Ich habe ein Dataset, das ein paar tausend Zeilen enthält und ich suche jede Zeile für bestimmten Text innerhalb der Strings: 7-16, 7-26, 7-36, 13414 , SHIPP, CONTAI ... usw. (mehr von ihnen unten gezeigt).InStr - nur in den ersten Teil der Zeichenfolge schauen
Das Problem ist, dass manchmal einige Teilenummern haben "# - ##" am Ende des Teils und nicht am Anfang und so das Makro es auch als "Container/PGSE Part/Trainer" wenn es klassifiziert wirklich nicht.
Also suche ich nach einer Syntax, die nur die ersten 4 Zeichen einer Zeichenkette in der Zelle betrachtet (nur für diejenigen, die die Teilenummern, nicht Wörter enthalten).
Zum Beispiel:
Wenn in einer Zelle mit „26.07 734372-102“ Ich würde suchen waren wollen sie es als „Container/PGSE Part/Trainer“ klassifizieren, in Spalte 51
Wenn in einer Zelle mit „MS3520 26.07 3“ ich nicht möge es klassifiziert sie als „Container/PGSE Teil/Trainer“ in Spalte 51 sehen waren, weil es am Ende der Zeichenfolge.
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
die linke Funktion verwenden. –
Verwenden Sie die Bedingung 'Wenn InStr (1, Zellen (rw, 8) .Wert," 7-16 ") = 1 Then'. Dies wird prüfen, ob '7-16' am Anfang steht. –