freshman2017
Goto Top

Excel Makro Hilfe

Moin Moin!

Ich würde gerne mit Excel - Kombinationen für Artikelnummern erstellen. Könnte hierbei bereits heraus finden, dass ein Makro genau das richtige wäre. Benötige jedoch eine Hilfestellung. Hat wer eine Idee?

Aus 7 Spalten sollen in einer anderen Spalte alle möglichen Kombinationen aufgelistet werden. Ist das mit einem Makro möglich oder liege ich da falsch?

Beispielkombination: XXXXXXXXXXXXXX

Spalte 1:
XX
XX
XX
etc.

Spalte 2:
XX
XX
XX
XX
etc.

Spalte 3:
XX
XX
XX
XX
etc.

Spalte 4:

Spalte 5:
...

Spalte 6:
...

Spalte 7
...

Content-Key: 391128

Url: https://administrator.de/contentid/391128

Printed on: April 16, 2024 at 20:04 o'clock

Member: Gizmo23
Gizmo23 Oct 31, 2018 at 06:08:35 (UTC)
Goto Top
Hallo freshman2017 ,

kannst Du Deine Frage noch etwas präzisieren?
Welche Kombinatorik soll angewendet werden?
Mitglied: 137443
Solution 137443 Oct 31, 2018 updated at 09:30:02 (UTC)
Goto Top
Ich tippe mal ins Blaue
Beispielmappe:
https://we.tl/t-VQ3Km0znb3

Gruß l.
Member: freshman2017
freshman2017 Oct 31, 2018 at 11:47:58 (UTC)
Goto Top
Zitat von @137443:

Ich tippe mal ins Blaue
Beispielmappe:
https://we.tl/t-VQ3Km0znb3

Gruß l.


Moin!

Ich hatte schon eine gute im Netz gefunden, jedoch bezieht sich diese nur auf 3 Spalten und ich weiß nicht, wie ich dies auf mehrere Spalten (7 Spalten erweiteren kann und erwirken, dass als Trennzeichen kein Leerzeichen erwirkt wird, also alles nebeneinander in Spalte 8):

Sub tt()
Dim i As Long, j As Long, k As Long
  For i = 2 To Cells(Rows.Count, 1).End(xlUp).Row
    For j = 2 To Cells(Rows.Count, 2).End(xlUp).Row
      For k = 2 To Cells(Rows.Count, 3).End(xlUp).Row
        Cells(Rows.Count, 4).End(xlUp).Offset(1) = _
            Cells(i, 1) & Cells(j, 2) & Cells(k, 3)
      Next k
    Next j
  Next i
End Sub
Mitglied: 137443
137443 Oct 31, 2018 updated at 11:50:45 (UTC)
Goto Top
Siehst du doch im Sheet, einfach die Anzahl der verschachtelten FOR-Schleifen um die Anzahl der Spalten erhöhen und SpaltenName bzw. Nummer und Ausgabe-Zelle anpassen.
Member: freshman2017
freshman2017 Oct 31, 2018 at 11:58:50 (UTC)
Goto Top
Zitat von @137443:

Siehst du doch im Sheet, einfach die Anzahl der verschachtelten FOR-Schleifen um die Anzahl der Spalten erhöhen und SpaltenName bzw. Nummer und Ausgabe-Zelle anpassen.

Du meinst so?

Sub tt()
Dim i As Long, j As Long, k As Long
  For i = 2 To Cells(Rows.Count, 1).End(xlUp).Row
    For j = 2 To Cells(Rows.Count, 2).End(xlUp).Row
      For k = 2 To Cells(Rows.Count, 3).End(xlUp).Row
      	For m = 2 To Cells(Rows.Count, 4).End(xlUp).Row
      		For n = 2 To Cells(Rows.Count, 5).End(xlUp).Row
      			For o = 2 To Cells(Rows.Count, 6).End(xlUp).Row
				      For p = 2 To Cells(Rows.Count, 7).End(xlUp).Row
        Cells(Rows.Count, 4).End(xlUp).Offset(1) = _
            Cells(i, 1) & Cells(j, 2) & Cells(k, 3) & Cells(m, 4) & Cells(n, 5) & Cells(o, 6) & Cells(o, 6) 	& Cells(p, 7)
      Next k
    Next j
  Next i
End Sub

Womit bewirke ich das die AUsgabe in Spalte 8 geschrieben werden? Und wo kann ich Einfluss auf das Leerzeichen nehmen?
Mitglied: 137443
137443 Oct 31, 2018 updated at 12:05:18 (UTC)
Goto Top
Jep.
Womit bewirke ich das die AUsgabe in Spalte 8 geschrieben werden?
Hier (ist schon schwer eine Nummer zu ändern ... face-confused)
        Cells(Rows.Count, 8).End(xlUp).Offset(1) = Cells(i, 1) & Cells(j, 2) & Cells(k, 3) & Cells(m, 4) & Cells(n, 5) & Cells(o, 6) & Cells(p, 7)
Und wo kann ich Einfluss auf das Leerzeichen nehmen?
Es werden keine Leerzeichen verknüpft, siehst du ja im Code! Wenn da Leerzeichen sind haben deine Spalten bereits dieses Leerzeichen(prüfen) und du musst sie bereinigen oder mit oben Trim() entfernen.
Member: freshman2017
freshman2017 Oct 31, 2018 at 12:08:01 (UTC)
Goto Top
Dass heisst so wäre komplett korrekt? Jetzt habe ich nur noch Zeile 2 und 10 angepasst.

Sub tt()
Dim i As Long, j As Long, k As Long, m As Long, n As Long, o As Long, p As Long
  For i = 2 To Cells(Rows.Count, 1).End(xlUp).Row
    For j = 2 To Cells(Rows.Count, 2).End(xlUp).Row
      For k = 2 To Cells(Rows.Count, 3).End(xlUp).Row
      	For m = 2 To Cells(Rows.Count, 4).End(xlUp).Row
      		For n = 2 To Cells(Rows.Count, 5).End(xlUp).Row
      			For o = 2 To Cells(Rows.Count, 6).End(xlUp).Row
				      For p = 2 To Cells(Rows.Count, 7).End(xlUp).Row
        Cells(Rows.Count, 8).End(xlUp).Offset(1) = _
            Cells(i, 1) & Cells(j, 2) & Cells(k, 3) & Cells(m, 4) & Cells(n, 5) & Cells(o, 6) & Cells(o, 6) 	& Cells(p, 7)
      Next k
    Next j
  Next i
End Sub
Mitglied: 137443
137443 Oct 31, 2018 updated at 12:14:45 (UTC)
Goto Top
Nö, doppelt gemoppelt, s.oben
Cells(o, 6) & Cells(o, 6)

back-to-topUnd die ganzen "Next" Anweisungen für die zuätzlichen Schleifen fehlen.


Ohh mannnnnnnnn....... VBA Grundkurs please!