Propiedad Range.Column (Excel)

Devuelve el número de la primera columna de la primera área en el rango especificado. Long de solo lectura.

Sintaxis

expresión. Columna

expresión Variable que representa un objeto Range.

Comentarios

Column A devuelve 1, column B devuelve 2, y así sucesivamente.

Para devolver el número de la última columna del rango, use la expresión siguiente:

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

Ejemplo

En este ejemplo se establece el ancho de columna de todas la columnas de la Hoja1 a 4 puntos.

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

En este ejemplo se eliminan las columnas vacías de un rango seleccionado.

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

Soporte técnico y comentarios

¿Tiene preguntas o comentarios sobre VBA para Office o esta documentación? Vea Soporte técnico y comentarios sobre VBA para Office para obtener ayuda sobre las formas en las que puede recibir soporte técnico y enviar comentarios.