Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1240to1244
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Inhaltsverzeichnis

Zeilen sortieren nach Zahl mit VBA

Zeilen sortieren nach Zahl mit VBA
Martin
Hallo zusammen
Ich habe in Zeile 2 die Spaltennummern, wie die Liste sortiert werden soll. z.B. in A2 steht 8, in B2 steht 15, in C2 steht 3, D2 ist leer, in E2 steht 33 etc.etc.
Jetzt soll die Liste entsprechend sortiert werden, dass die Spalte A (wo ja in A2 die 8 steht) in die 8. Spalte verschoben wird, Spalte B in die 15., Spalte C in die 3., Spalte D gelöscht, Spalte E in 33. usw.
Besten Dank im voraus für Eure Hilfe.
Martin

1
Beitrag zum Forumthread
Beitrag zu diesem Forumthread

Betreff
Benutzer
Anzeige
AW: Zeilen sortieren nach Zahl mit VBA
15.12.2011 23:49:50
Josef

Hallo Martin,
' **********************************************************************
' Modul: Modul1 Typ: Allgemeines Modul
' **********************************************************************

Option Explicit

Sub mixedColumns()
  Dim lngLastCol As Long, lngLastRow As Long, lngIndex As Long
  Dim vntCols() As Variant
  
  On Error GoTo ErrExit
  GMS
  
  With ActiveSheet
    lngLastCol = .Cells(2, .Columns.Count).End(xlToLeft).Column
    Redim vntCols(1 To lngLastCol)
    For lngIndex = 1 To lngLastCol
      lngLastRow = .Cells(.Rows.Count, lngIndex).End(xlUp).Row
      vntCols(lngIndex) = .Range(.Cells(1, lngIndex), .Cells(lngLastRow, lngIndex))
    Next
    .Cells.ClearContents
    For lngIndex = 1 To lngLastCol
      If Not IsEmpty(vntCols(lngIndex)(2, 1)) Then
        If IsNumeric(vntCols(lngIndex)(2, 1)) Then
          .Cells(1, vntCols(lngIndex)(2, 1)).Resize(UBound(vntCols(lngIndex)), 1) = vntCols(lngIndex)
        End If
      End If
    Next
  End With
  
  ErrExit:
  GMS True
  
End Sub


Public Sub GMS(Optional ByVal Modus As Boolean = False)
  
  Static lngCalc As Long
  
  With Application
    .ScreenUpdating = Modus
    .EnableEvents = Modus
    .DisplayAlerts = Modus
    .EnableCancelKey = IIf(Modus, 1, 0)
    If Not Modus Then lngCalc = .Calculation
    If Modus And lngCalc = 0 Then lngCalc = -4105
    .Calculation = IIf(Modus, lngCalc, -4135)
    .Cursor = IIf(Modus, -4143, 2)
    
  End With
  
End Sub



« Gruß Sepp »

Anzeige

302 Forumthreads zu ähnlichen Themen

Anzeige
Anzeige
Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige