ich habe folgendes Problem:
Ich suche in einem Sheet nach Auftragsnummern mit einem bestimmten Datum. Diese Aufträge sind in einer Spalte mit Status "A" oder Status "M" bezeichnet.
Bei Status "A" werden die Aufträge nur hochgezählt.
Bei Status "B" werden die Aufträge auch hochgezählt, zusätzlich muss in einem weiteren Sheet nach diesen Aufträgen gesucht werden, um weitere Informationen darüber zu bekommen.
Die Sheets sind Exporte aus SAP.
Folgenden Code habe ich dafür geschrieben:
(Die Worksheets sind vorher definiert)
Dim b As Object
Dim c As Object
Dim Firstrow As Integer
For Spalte = Anfangsspalte To Endspalte
Set c = wsSAP.Range("A1:A2000").Find(ws.Cells(3, Spalte), LookIn:=xlValues)
If Not c Is Nothing Then
Firstrow = c.Row
Do
ws.Cells(4, Spalte) = ws.Cells(4, Spalte) + wsSAP.Cells(c.Row, 6)
If wsSAP.Cells(c.Row, 4) = "A" Then ws.Cells(5, Spalte) = ws.Cells(5, Spalte) + wsSAP.Cells(c.Row, 6)
If wsSAP.Cells(c.Row, 4) = "M" Then
ws.Cells(8, Spalte) = ws.Cells(8, Spalte) + 1
ws.Cells(6, Spalte) = ws.Cells(6, Spalte) + wsSAP.Cells(c.Row, 6)
Set b = wsVorg.Range("A1:A2000").Find(wsSAP.Cells(c.Row, 2), LookIn:=xlValues)
If Not b Is Nothing Then
If wsVorg.Cells(b.Row, 4) Like "*1/6*" Then
ws.Cells(10, Spalte) = ws.Cells(10, Spalte) + 1
ws.Cells(19, Spalte) = ws.Cells(19, Spalte) + 1
End If
If wsVorg.Cells(b.Row, 4) Like "*1/3*" Then
ws.Cells(11, Spalte) = ws.Cells(11, Spalte) + 1
ws.Cells(17, Spalte) = ws.Cells(17, Spalte) + 1
End If
If wsVorg.Cells(b.Row, 4) Like "*1/2*" Then
ws.Cells(12, Spalte) = ws.Cells(12, Spalte) + 1
ws.Cells(17, Spalte) = ws.Cells(17, Spalte) + 1
ws.Cells(18, Spalte) = ws.Cells(18, Spalte) + 1
End If
If wsVorg.Cells(b.Row, 4) Like "*2/3*" Then
ws.Cells(13, Spalte) = ws.Cells(13, Spalte) + 1
ws.Cells(17, Spalte) = ws.Cells(17, Spalte) + 1
ws.Cells(18, Spalte) = ws.Cells(18, Spalte) + 1
ws.Cells(19, Spalte) = ws.Cells(19, Spalte) + 1
End If
If wsVorg.Cells(b.Row, 4) Like "*5/6*" Then
ws.Cells(14, Spalte) = ws.Cells(14, Spalte) + 1
ws.Cells(17, Spalte) = ws.Cells(17, Spalte) + 1
ws.Cells(18, Spalte) = ws.Cells(18, Spalte) + 1
ws.Cells(19, Spalte) = ws.Cells(19, Spalte) + 2
End If
If wsVorg.Cells(b.Row, 4) Like "*1/1*" Then
ws.Cells(15, Spalte) = ws.Cells(15, Spalte) + 1
ws.Cells(17, Spalte) = ws.Cells(17, Spalte) + 1
ws.Cells(18, Spalte) = ws.Cells(18, Spalte) + 1
ws.Cells(19, Spalte) = ws.Cells(19, Spalte) + 3
End If
End If
End If
Set c = wsSAP.Range("A1:A2000").FindNext(c)
Loop While Not c Is Nothing And c.Row Firstrow
End If
An der fett markierten Zeile steigt das Programm mit 'Objektvariable nicht festgelegt' stehen, aber nur wenn der Status = "M" ist und die innere Suche über Set b läuft.
Ich kann mir das nicht erklären und weiß keine Lösung.
Kann mir jemand weiter helfen.
Vielen Dank