Range.Column-Eigenschaft (Excel)

Gibt die erste Spalte am Anfang des angegebenen Bereichs als Zahl zurück. Schreibgeschützter Long-Wert.

Syntax

Ausdruck. Spalte

Ausdruck Eine Variable, die ein Range-Objekt darstellt.

Bemerkungen

Spalte A entspricht dem Rückgabewert 1, Spalte B dem Wert 2 usw.

Die Zahl der letzten Spalte im Bereich können Sie folgendermaßen zurückgeben:

myRange.Columns(myRange.Columns.Count).Column

Beispiel

In diesem Beispiel wird die Breite jeder Spalte in Sheet1 auf 4 Punkt festgelegt.

For Each col In Worksheets("Sheet1").Columns 
    If col.Column Mod 2 = 0 Then 
        col.ColumnWidth = 4 
    End If 
Next col

In diesem Beispiel werden die leeren Spalten aus einem ausgewählten Bereich gelöscht.

Sub Delete_Empty_Columns()
    'The range from which to delete the columns.
    Dim rnSelection As Range
    
    'Column and count variables used in the deletion process.
    Dim lnLastColumn As Long
    Dim lnColumnCount As Long
    Dim lnDeletedColumns As Long
    
    lnDeletedColumns = 0
    
    'Confirm that a range is selected, and that the range is contiguous.
    If TypeName(Selection) = "Range" Then
        If Selection.Areas.Count = 1 Then
            
            'Initialize the range to what the user has selected, and initialize the count for the upcoming FOR loop.
            Set rnSelection = Application.Selection
            lnLastColumn = rnSelection.Columns.Count
        
            'Start at the far-right column and work left: if the column is empty then
            'delete the column and increment the deleted column count.
            For lnColumnCount = lnLastColumn To 1 Step -1
                If Application.CountA(rnSelection.Columns(lnColumnCount)) = 0 Then
                    rnSelection.Columns(lnColumnCount).Delete
                    lnDeletedColumns = lnDeletedColumns + 1
                End If
            Next lnColumnCount
    
            rnSelection.Resize(lnLastColumn - lnDeletedColumns).Select
        Else
            MsgBox "Please select only one area.", vbInformation
        End If
    Else
        MsgBox "Please select a range.", vbInformation
    End If
    
    'Turn screen updating back on.
    Application.ScreenUpdating = True

End Sub

Support und Feedback

Haben Sie Fragen oder Feedback zu Office VBA oder zu dieser Dokumentation? Unter Office VBA-Support und Feedback finden Sie Hilfestellung zu den Möglichkeiten, wie Sie Support erhalten und Feedback abgeben können.