Sortierungsproblem in Excel VBA
25.04.2018 20:03:38
Anton
vielleicht kann jemand von euch helfen. Ich komme da leider nicht weiter. Ich versuche mit Hilfe von Excel VBA verschiedene Seriennummer in verschiedenen Spalten zu sortieren. Leider funktionieren nicht alle Seriennummern und ich weiss auch nicht wieso.
SG706311x muss in Spalte 1, das stimmt auch soweit.
SG706011x muss in Spalte 2, leider sortiert sich das auch in Spalte 1 warum auch immer.
Spalte 1 Spalte 2
SG706011x SG706011x
SG706311x
Ich weiss leider nicht wie ich es besser erklären kann, ich hoffe ich versteht es wenn ihr ein Teil des Quelltextes anschaut.
SnummerTeil = Mid(Snummer, 1, 2)
If KundeAuswahl = Kunde And SnummerTeil "FR" Then
Nr = Nr + 1
If SnummerTeil = "SE" Then
'InfoBox.AddItem "SE erkannt"
NrSamSP3 = NrSamSP3 + 1
With Application.Workbooks(ExtDateiNameSam).Worksheets(NeuerTabErstellenSam2)
.Cells(TabellenAnfang + NrSamSP3, 6).Value = Snummer
End With
End If
XFilter = Mid(Snummer, 9, 1)
If XFilter = "x" And SnummerTeil = "SG" Then
InfoBox.AddItem "Altes Schälgerät " & Snummer
If XFilter = "x" And SnummerTeil = "SG" And Mid(Snummer, 6, 1) = 3 Then
'InfoBox.AddItem "63 erkannt"
GoTo SG63
End If
If XFilter = "x" And SnummerTeil = "SG" And Mid(Snummer, 6, 1) = 0 Then
'InfoBox.AddItem "315 erkannt"
GoTo SG315
End If
If Mid(Snummer, 1, 2) = "RA" Then
'InfoBox.AddItem "RA erkannt"
NrSamSP4 = NrSamSP4 + 1
With Application.Workbooks(ExtDateiNameSam).Worksheets(NeuerTabErstellenSam2)
.Cells(TabellenAnfang + NrSamSP4, 8).Value = Snummer
End With
End If
If Mid(Snummer, 1, 2) = "TL" Then
'InfoBox.AddItem "TL erkannt"
GoTo SGTL
End If
Else
'InfoBox.AddItem Time & "- FilterTyp " & SNummerTeilTyp
SNummerTeilTyp = Mid(Snummer, 5, 2)
If SNummerTeilTyp = "25" Then
SG315: NrSamSP2 = NrSamSP2 + 1
'InfoBox.AddItem Time & "- Friamat 3"
With Application.Workbooks(ExtDateiNameSam).Worksheets(NeuerTabErstellenSam2)
'.Cells(TabellenAnfang + NrSamSP2, 5).Value = NrSamSP2
.Cells(TabellenAnfang + NrSamSP2, 4).Value = Snummer
End With
End If
If SNummerTeilTyp = "20" And SnummerTeil "SE" Then
SG63: NrSamSP1 = NrSamSP1 + 1
'InfoBox.AddItem Time & "- Friamat 1 o. 2"
With Application.Workbooks(ExtDateiNameSam).Worksheets(NeuerTabErstellenSam2)
'.Cells(TabellenAnfang + NrSamSP1, 2).Value = NrSamSP1
.Cells(TabellenAnfang + NrSamSP1, 2).Value = Snummer
End With
End If
Select Case SNummerTeilTyp
Case 40, 42, 47, 48, 60
SGTL: NrSamSP6 = NrSamSP6 + 1
'InfoBox.AddItem Time & "- FWSGA/Tolpload"
With Application.Workbooks(ExtDateiNameSam).Worksheets(NeuerTabErstellenSam2)
'.Cells(TabellenAnfang + NrSamSP5, 14).Value = NrSamSP5
.Cells(TabellenAnfang + NrSamSP6, 12).Value = Snummer
End With
Case 80, 82, 85
NrSamSP5 = NrSamSP5 + 1
'InfoBox.AddItem Time & "- FWSG 110/180/225"
With Application.Workbooks(ExtDateiNameSam).Worksheets(NeuerTabErstellenSam2)
'.Cells(TabellenAnfang + NrSamSP5, 14).Value = NrSamSP5
.Cells(TabellenAnfang + NrSamSP5, 10).Value = Snummer
End With
End Select
End If
End If
Summe = NrSamSP1 + NrSamSP2 + NrSamSP3 + NrSamSP4 + NrSamSP5
Next z
NrSamSP1 = 0
NrSamSP2 = 0
NrSamSP3 = 0
NrSamSP4 = 0
NrSamSP5 = 0
NrSamSP6 = 0
'TabellenName = NeuerTabErstellen
With Application.Workbooks(ExtDateiNameSam).Worksheets(NeuerTabErstellenSam2)
.Cells(42, 2).Value = "Geräteanzahl: "
.Cells(42, 4).Cells(44, 2).HorizontalAlignment = xlLeft
.Cells(42, 4).Value = Summe
End With
Call TabelleZeichnenSamSG(ExtDateiNameSam, NeuerTabErstellenSam2, TabellenAnfang)
Nr = 0
Next zKunde
Ich bin für jede hilfreiche Idee dankbar.
Danke.
VG Anton