Ich habe die Notwendigkeit, einen Teil einer horizontalen Liste vertikal zu drehen. Ich habe versucht, TRANSPOSE ohne Erfolg zu verwenden.Machen Sie horizontale Liste vertikal in Excel
Mit einem VBA-Skript habe ich leere Zeilen unterhalb der vier oder fünfstelligen Produktnummer eingefügt. Und ich möchte die im Bild gezeigten Werte verschieben (oder kopieren/einfügen).
Excel-Liste
I modifiziert, um ein Skript VBA mir gegeben (Kredit TheAtomicOption gegeben), aber Excel Ständen wenn ich laufe es:
Sub Sizes()
'figure out how far down data goes
Range("A1").Select
Selection.End(xlDown).Select
Dim endrow
endrow = Selection.Row
'always start in the correct column
Range("D1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(0, -1).Activate
Dim rownumber
'loop through all data
Do While ActiveCell.Row < endrow
'Store cell of current base name
rownumber = ActiveCell.Row
'loop through empty cells and set formula if cell isn't empty
Do While True
ActiveCell.Offset(1, 0).Activate
'if next cell isn't empty, isn't past the end of the list, go to outer loop
If ActiveCell.Formula = "" And ActiveCell.Row <= endrow Then
ActiveCell.Offset(0, 1).Formula = "=E(" & rownumber & ")"
ActiveCell.Offset(1, 0).Activate
If ActiveCell.Formula = "" And ActiveCell.Row <= endrow Then
ActiveCell.Offset(0, 1).Formula = "=F(" & rownumber & ")"
ActiveCell.Offset(1, 0).Activate
If ActiveCell.Formula = "" And ActiveCell.Row <= endrow Then
ActiveCell.Offset(0, 1).Formula = "=G(" & rownumber & ")"
ActiveCell.Offset(1, 0).Activate
If ActiveCell.Formula = "" And ActiveCell.Row <= endrow Then
ActiveCell.Offset(0, 1).Formula = "=H(" & rownumber & ")"
ActiveCell.Offset(1, 0).Activate
If ActiveCell.Formula = "" And ActiveCell.Row <= endrow Then
ActiveCell.Offset(0, 1).Formula = "=I(" & rownumber & ")"
ActiveCell.Offset(1, 0).Activate
Else
Exit Do
End If
End If
End If
End If
End If
Loop
Loop
End Sub
Irgendwelche Vorschläge, wie man zu lösen, und wie das Skript zu verbessern?
EDIT: Spalte A ist nur eine Stütze Spalte für Selection.End(xlDown).Select
Spalte B ist ein Zähler für die Größen. Es ist für das anfängliche Skript, das neue Zeilen eingefügt hat. Spalte C ist Artikelnummer/Produkt ID Spalte D ist die Spalte, in der alle Größen aufgeführt werden sollen. Spalte E-I und in der Reihe mit SKU ist, wo die Größen jetzt aufgeführt sind.
Edit 2 aussehen sollte: von QHarr
Lösung, dank Skript.
Option Explicit
Sub Sizes()
Dim wb As Workbook
Dim ws As Worksheet
'figure out how far down data goes
Dim endrow As Long
Dim rownumber As Long
Set wb = ThisWorkbook
Set ws = wb.Sheets("Sheet1") ' Modified the sheet name
With ws
endrow = .Cells(.Rows.Count, "A").End(xlUp).Row
'always start in the correct column
.Cells(.Cells(1, "D").End(xlDown).Row, "D").Offset(, -1).Activate
'loop through all data
Do While ActiveCell.Row < endrow
'loop through empty cells and set formula if cell isn't empty
Do While ActiveCell.Row <= endrow
'Set rownumer at new product id
rownumber = ActiveCell.Row
ActiveCell.Offset(1, 0).Activate
'if next cell isn't empty, isn't past the end of the list, go to outer loop
If ActiveCell.Formula = "" And ActiveCell.Row <= endrow Then
ActiveCell.Offset(0, 1).Formula = "=E" & rownumber
ActiveCell.Offset(1, 0).Activate
If ActiveCell.Formula = "" And ActiveCell.Row <= endrow Then
ActiveCell.Offset(0, 1).Formula = "=F" & rownumber
ActiveCell.Offset(1, 0).Activate
If ActiveCell.Formula = "" And ActiveCell.Row <= endrow Then
ActiveCell.Offset(0, 1).Formula = "=G" & rownumber
ActiveCell.Offset(1, 0).Activate
If ActiveCell.Formula = "" And ActiveCell.Row <= endrow Then
ActiveCell.Offset(0, 1).Formula = "=H" & rownumber
ActiveCell.Offset(1, 0).Activate
If ActiveCell.Formula = "" And ActiveCell.Row <= endrow Then
ActiveCell.Offset(0, 1).Formula = "=I" & rownumber
ActiveCell.Offset(1, 0).Activate
Else
Exit Do
End If
End If
End If
End If
End If
Loop
Loop
End With
End Sub
Einige Startpunkte: Wenn Sie die Option explizit aktiviert haben, dann haben Sie Fehler, weil Sie Ihre Variablentypen nicht deklarieren, z. Dim Endrow sollte so etwas wie Dim endrow so lang sein. Abhängig davon, wie Ihre Daten strukturiert sind (ob Spalten in den Spalten vorhanden sind), müssen Sie möglicherweise die Endzeile anpassen. Willst du damit sagen, dass es ohne anzuhalten weiterläuft? Das kann bedeuten, dass du keine Ausgangsbedingung für deine Do-Schleife hast oder sie nicht erfüllt wird. Oder gibt es eine Fehlermeldung? – QHarr
Wie wäre es mit Screenshots der eigentlichen Originaldaten und dem gewünschten Ergebnis? –
@QHarr: Keine Lücken in den Spalten. Lücken in den Reihen obwohl. Durch das Abwürgen meine ich, dass das Skript weiter läuft, der Bildschirm wird grau und ich bekomme die Meldung, dass Excel nicht mehr reagiert. – hedburgaren