Probleme bei Programmierung
ray
ich schaffe es einfach nicht, zwei codes zu einem zu machen. Kann mir jemand helfen und am besten auch erklären was ich falsch mache:
Diese Beiden codes sollen zu einem werden (Code1 füllt ComboBox1 und Code2 füllt ComboBox2 aus der selben Quelle):
1. Code
'#### ComboBox mit ALLEN Mänglen füllen START ####
Dim wbk As Workbook
Dim wks As Worksheet
Dim vRow As Variant
Dim iRow As Integer, iRowT As Integer, iRowL As Integer
Application.ScreenUpdating = False
Set wbk = Workbooks.Open("F:\daten\mängelliste.xls")
Set wks = wbk.Sheets(1)
iRowL = Cells(Rows.Count, 8).End(xlUp).Row
Workbooks.Add
For iRow = 1 To iRowL
vRow = Application.Match(wks.Cells(iRow, 8).Value, Columns(1), 0)
If IsError(vRow) Then
iRowT = iRowT + 1
Cells(iRowT, 1).Value = wks.Cells(iRow, 8).Value
End If
Next iRow
Range("a1").CurrentRegion.Sort _
key1:=Range("a1"), order1:=xlAscending, Header:=xlNo
With cbMängelliste
.List = Range("A1").CurrentRegion.Value
If .ListCount > 0 Then .ListIndex = 0
End With
ActiveWorkbook.Close savechanges:=False
wbk.Close
Set wbk = Nothing
Set wks = Nothing
Application.ScreenUpdating = True
'#### ComboBox mit Mänglen füllen ENDE ####
Code2:If wks.Cells(iRow, 3).Value = "111" Then
vRow = Application.Match(wks.Cells(iRow, 8).Value, Columns(1), 0)
If IsError(vRow) Then
iRowT = iRowT + 1
Cells(iRowT, 1).Value = wks.Cells(iRow, 8).Value
End If
End If
Next iRow
Wenn ich den Zeilen des Code2 mit den entsprechenden Zeilen von Code1 austausche, dann funzt dieser. Baue ich das jetzt aber so zusammen geht nix:
'#### ComboBox mit ALLEN Mänglen füllen START ####
Dim wbk As Workbook
Dim wks As Worksheet
Dim vRow As Variant
Dim iRow As Integer, iRowT As Integer, iRowL As Integer
Application.ScreenUpdating = False
Set wbk = Workbooks.Open("F:\daten\mängelliste.xls")
Set wks = wbk.Sheets(1)
iRowL = Cells(Rows.Count, 8).End(xlUp).Row
Workbooks.Add
For iRow = 1 To iRowL
vRow = Application.Match(wks.Cells(iRow, 8).Value, Columns(1), 0)
If IsError(vRow) Then
iRowT = iRowT + 1
Cells(iRowT, 1).Value = wks.Cells(iRow, 8).Value
End If
Next iRow
Range("a1").CurrentRegion.Sort _
key1:=Range("a1"), order1:=xlAscending, Header:=xlNo
With cbMängelliste
.List = Range("A1").CurrentRegion.Value
If .ListCount > 0 Then .ListIndex = 0
End With
'jetzt nochmal nur mit WhgNr
Set wks = wbk.Sheets(1)
iRowL = Cells(Rows.Count, 8).End(xlUp).Row
Workbooks.Add
For iRow = 1 To iRowL
If wks.Cells(iRow, 3).Value = "111" Then
vRow = Application.Match(wks.Cells(iRow, 8).Value, Columns(1), 0)
If IsError(vRow) Then
iRowT = iRowT + 1
Cells(iRowT, 1).Value = wks.Cells(iRow, 8).Value
End If
End If
Next iRow
Range("a1").CurrentRegion.Sort _
key1:=Range("a1"), order1:=xlAscending, Header:=xlNo
With cbMängelAlle
.List = Range("A1").CurrentRegion.Value
If .ListCount > 0 Then .ListIndex = 0
End With
ActiveWorkbook.Close savechanges:=False
wbk.Close
Set wbk = Nothing
Set wks = Nothing
Application.ScreenUpdating = True
'#### ComboBox mit Mänglen füllen ENDE ####
Viele Grüße aus Hamburg
Ray