Range プロパティ (Excel)Range.Column property (Excel)

指定された範囲の最初の領域の最初の列の番号を返します。Returns the number of the first column in the first area in the specified range. 取得のみ可能な Long 値です。Read-only Long.



expressionRange オブジェクトを表す変数です。expression A variable that represents a Range object.


列番号は、列 A のときは 1、列 B のときは 2 のように、数値で返されます。Column A returns 1, column B returns 2, and so on.

対象セル範囲の最後の列番号を求めるには、次のように式を指定します。To return the number of the last column in the range, use the following expression.



次の使用例は、シート 1 で 1 列ごとに幅を 4 に設定します。This example sets the column width of every other column on Sheet1 to 4 points.

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

次の使用例は、選択された範囲から空の列を削除します。This example deletes the empty columns from a selected range.

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
                    lnDeletedColumns = lnDeletedColumns + 1
                End If
            Next lnColumnCount
            rnSelection.Resize(lnLastColumn - lnDeletedColumns).Select
            MsgBox "Please select only one area.", vbInformation
        End If
        MsgBox "Please select a range.", vbInformation
    End If
    'Turn screen updating back on.
    Application.ScreenUpdating = True

End Sub

サポートとフィードバックSupport and feedback

Office VBA またはこの説明書に関するご質問やフィードバックがありますか?Have questions or feedback about Office VBA or this documentation? サポートの受け方およびフィードバックをお寄せいただく方法のガイダンスについては、Office VBA のサポートおよびフィードバックを参照してください。Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.