VBA Range Column: How to Reference Columns

VBA & macros · Updated November 2, 2026

VBA Range Column: How to Reference Columns

In VBA, reference a whole worksheet column with Columns("C") or Range("C:C"); to get the column containing a particular cell, use Range("C5").EntireColumn. Qualify the reference with a worksheet, such as Worksheets("Data").Columns("C"), so the code targets the intended sheet.

What a VBA range column means

A range is one or more cells that VBA can read, format, or change. A column reference is a range that represents either a full worksheet column or the portion of a range occupying one column. The distinction matters: Range("C:C") refers to every cell in column C, while Range("C1:C20") refers only to rows 1 through 20.

Excel’s worksheet column labels are letters, but VBA also accepts numeric column positions. Column A is 1, B is 2, and C is 3. On current Windows versions of Excel, a worksheet has 16,384 columns, ending at XFD. Choose a letter when it makes the code easier to read; use a number when the column position comes from a variable or calculation.

  • ws.Columns("C") refers to the whole of column C on worksheet ws.
  • ws.Columns(3) also refers to the whole of column C.
  • ws.Range("C:C") is another explicit way to refer to that full column.
  • ws.Range("C5").EntireColumn returns the full column containing cell C5.

How Columns and Range.Columns work

Columns is a property that returns a range of columns from a worksheet or another range. On a worksheet, ws.Columns(3) means the third worksheet column. On a range, the index is relative to that range: for example, the first column of ws.Range("B2:C10") is column B. If you need to turn the selected portion into a full worksheet column, add .EntireColumn.

That relative indexing can be useful in reusable procedures. Suppose a routine receives a multi-column block and must work with the block’s leftmost column regardless of where the block begins. The routine can use someRange.Columns(1). It does not have to assume the block starts in column A. In contrast, ws.Columns(1) always means worksheet column A.

The EntireColumn property is helpful when you start with a cell or a small range and want the full worksheet column associated with it. For instance, ws.Range("D7").EntireColumn identifies all of column D. It does not mean “the cell’s current data area”; it means the entire sheet column.

Choosing a reference for the task

Use the narrowest reference that fits the job. A full-column reference is convenient for column-wide operations such as setting a width, applying a number format, or inserting a column. A limited range is often more suitable when reading or changing data rows, because it makes the intended scope clear and avoids touching unrelated cells.

  • Use ws.Columns("C") when you mean a complete worksheet column and want a readable column label.
  • Use ws.Columns(columnNumber) when the column number is stored in a variable, such as columnNumber = 3.
  • Use ws.Range("C:C") when a familiar A1-style address makes the target clearest.
  • Use ws.Range("C2:C50") when the operation should stop at a known last row.
  • Use someRange.Columns(1) when the desired column is relative to a block that may move.

For example, with the worksheet stored in an object variable named ws, ws.Columns("C").ColumnWidth = 18 sets the width of column C to 18. The same column can be given a number format with ws.Columns("C").NumberFormat = "0.00". The format string is a VBA string; the assignment affects the cells in the selected column.

Qualifying the worksheet correctly

In a standard module, an unqualified expression such as Range("C:C") refers to the active worksheet. The active sheet can change when a user clicks a tab or when another part of a macro activates a different sheet. This can make code appear to work in one situation and modify the wrong sheet in another.

For predictable results, set a worksheet variable and attach every range reference to it. For example, Set ws = ThisWorkbook.Worksheets("Data") makes ws.Columns("C") refer to column C on the sheet named Data in the workbook containing the macro. If the macro is stored in a different workbook from the data, you may need to refer to the workbook that actually contains the worksheet rather than use ThisWorkbook.

A worksheet’s Columns property and a range’s Columns property are not interchangeable in every context. The worksheet version identifies sheet columns. The range version identifies columns within the specified range, using relative positions. Qualifying the object before the property makes this context easier to see and helps prevent accidental dependence on the active sheet.

Practical VBA example

This macro changes the width and number format of column C on a worksheet named Data. It does not select the sheet or rely on the active worksheet.

Sub FormatDataColumn()
    Dim ws As Worksheet

    ' Point to the worksheet that contains the data.
    Set ws = ThisWorkbook.Worksheets("Data")

    ' Set the width and display two decimal places.
    ws.Columns("C").ColumnWidth = 18
    ws.Columns("C").NumberFormat = "0.00"
End Sub

Before running any macro, save a copy of the workbook. VBA changes cannot be reversed with Ctrl+Z, even if the change seems simple. On Windows, open the Visual Basic Editor with Alt+F11; on Mac, the usual equivalent is Option+F11, although some keyboards require the Fn key. To run a macro from Excel, use the Developer tab’s Macros command; if the Developer tab is hidden, enable it in Excel’s ribbon settings. Excel for the web can open a workbook containing macros but does not run VBA macros.

Changing a cell’s column or a whole column

A common point of confusion is the difference between a cell reference and a column reference. ws.Range("C5") refers to one cell. ws.Range("C5").EntireColumn refers to all of column C. Likewise, ws.Range("C5:D5").EntireColumn refers to both full columns C and D, because the starting range spans two columns.

Use the full-column object only when a whole-column operation is intended. For example, ws.Columns("C").ClearContents removes values and formulas throughout column C while leaving formatting in place. This is a broad, destructive change, so confirm the target sheet and column before running it. To clear only rows 2 to 50, use a bounded reference such as ws.Range("C2:C50").ClearContents instead.

Similarly, a full-column reference can be used for operations such as Insert, Delete, or AutoFit, but the effects differ. Inserting or deleting a whole column shifts other worksheet content. AutoFit adjusts the width based on the relevant cell contents. Check whether formulas, labels, or other data to the right depend on the existing layout before inserting or deleting columns.

Common errors and how to avoid them

  • Wrong sheet: An unqualified Range or Columns reference can use the active sheet. Prefix it with a worksheet variable or an explicit worksheet reference.
  • Wrong column number: VBA numbering starts at 1, not 0. Therefore, Columns(3) is C, not D.
  • Confusing relative and absolute positions: ws.Columns(2) means worksheet column B, but ws.Range("D1:F10").Columns(2) means the second column within that range, which is E.
  • Using an entire column for a small job: A whole-column change can affect far more cells than intended. Specify row limits when only a data block should change.
  • Misspelling a worksheet name: A worksheet lookup such as Worksheets("Data") fails if the tab has a different name. Check the tab name, including spaces.
  • Assuming macro changes can be undone: VBA actions clear Excel’s ordinary undo history. Save a backup before running code that edits a workbook.

If a column variable may be outside the worksheet’s valid range, validate it before using it. A column number must be at least 1 and no greater than the worksheet’s final column number. This is especially useful when the number comes from user input or a calculation rather than a fixed value.

VBA columns compared with worksheet selection

VBA can select a column, but selecting it is usually unnecessary. For example, ws.Columns("C").Select makes the column active, but a direct statement such as ws.Columns("C").ColumnWidth = 18 performs the operation without changing the user’s selection. Direct references are generally easier to maintain and work better when a macro runs in the background or interacts with several sheets.

Selection-based code can still be appropriate when the goal is to leave the user looking at a particular column. However, it often requires activating the worksheet first, which adds more dependence on workbook state. Prefer direct object references for formatting, copying, reading, and clearing unless the visible selection is itself part of the intended result.

VBA range references are also different from formulas typed into worksheet cells. A worksheet formula uses cell addresses as part of a calculation, while VBA uses a Range object to tell a procedure which cells to act on. The address text may look similar, but VBA adds object properties and methods such as .Value, .NumberFormat, and .EntireColumn.

Frequently Asked Questions

How do I refer to column A in VBA?
Use Columns("A") or Columns(1) on the intended worksheet. For example, ws.Columns("A") clearly targets column A on worksheet object ws.

What is the difference between Columns(1) and Range(“A:A”)?
When used on a worksheet, both refer to the full first column, column A. Columns(1) uses a numeric index; Range("A:A") uses an A1-style address. In a range context, someRange.Columns(1) means the first column within that range, not necessarily worksheet column A.

How do I get the entire column from a cell?
Use the cell’s EntireColumn property. For example, ws.Range("D7").EntireColumn returns all of column D, not just the cell D7.

Can I use a column letter stored in a variable?
Yes. If columnLetter contains the text C, then ws.Columns(columnLetter) refers to column C. Validate externally supplied values before using them, so an invalid letter or address does not cause a runtime error.

Why does Range(“A:A”) act on the wrong worksheet?
Without a worksheet qualifier, VBA uses the active sheet in the usual standard-module context. Reference the intended sheet explicitly, such as ThisWorkbook.Worksheets("Data").Range("A:A"), or assign that worksheet to a variable and use the variable.

Related

Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.

More in VBA & macros

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.