Ich Hoffe mich einiger maßen verständlich gemacht zu haben
hm... um in der Schreibweise des vorhandenen Codes zu bleiben:
Private Sub CMD_ImportSel_Click()
Dim i As Long, bl As Boolean, j As Long
bl = False
For i = 0 To Me.ListBoxB.ListCount - 1
If Me.ListBoxB.Selected(i) = True Then
For j = 0 To Me.ListBoxA.ListCount - 1
If Me.ListBoxB.Column(0, i) = Me.ListBoxA.Column(0, j) Then
bl = True
Exit For
End If
Next
If bl = False Then
With Me.ListBoxA
.AddItem " "
.List(.ListCount - 1, 0) = Me.ListBoxB.Column(0, i)
.List(.ListCount - 1, 1) = Me.ListBoxB.Column(1, i)
End With
Else
MsgBox "Field already added", vbInformation, "Note:"
End If
End If
Next
End Sub
Wie kann ich dann, die Bezüge zwischen die Listboxen zu den Bereichen herstellen?
z.B:
Private Sub CMD_Copy_Click()
Dim sc As Range, st As Range 'source / target
If Me.ListBoxB.ListIndex < 0 Or Me.ListBoxB.ListIndex < 0 Then Exit Sub
With Sheets("Export") 'Spalte AJ ist Leerspalte, sonst direkte Bereiche für FIND !!
Set sc = .Range("AK1").CurrentRegion.Find(Me.ListBoxB.Value)
If Not sc Is Nothing Then Set sc = Range(sc.Offset(0, -3), sc.Offset(36, 31))
Set st = .UsedRange.Find(Me.ListBoxA.Value)
If Not st Is Nothing Then Set st = Range(st.Offset(0, -3), st.Offset(36, 31))
If Not sc Is Nothing And Not st Is Nothing Then
Select Case MsgBox("von " & sc.Address & " - nach " & st.Address, _
vbOKCancel Or vbInformation Or vbDefaultButton1, "CMD_Copy")
Case vbOK
sc.Copy
st.PasteSpecial Paste:=xlPasteValues
Case vbCancel
'
End Select
Else
Call MsgBox("Fehler im Bereich!", vbCritical, "Abbruch CMD_Copy")
End If
End With
End Sub
Nur kollidiert das Suchergebnis, wenn schon einmal kopiert wurde?
Nachdem die Datenstruktur in so gleichmäßigen Blöcken vorliegt:
- hätte ich das ganze Projekt mit benannten Bereichen (1a, 1b, .... 15b) aufgezogen!
|