How to Select Columns with VBA (3 Easy Ways)


Download the Practice Workbook

3 Ways to Select Columns with VBA

Consider the List of Company Information dataset shown in the B4:D12 cells, which contains the Organization Name, Industry, and Country columns. We want to select the columns by applying VBA code.

Dataset for vba columns select

Method 1 – Selecting a Single Column with VBA Code


  • Navigate to the Developer tab and click on the Visual Basic button.

Opening Visual Basic from developer tab

  • This opens the Visual Basic Editor in a new window.
  • Go to the Insert tab and select Module.

Inserting Module

  • Copy the code from here and paste it into the window as shown below.
Sub select_single_col()


End Sub

VBA code for selecting single column

Code Breakdown

Now, in the following section, we’ll explain the VBA code used to select columns with VBA.

  • The subroutine’s name is select_single_col().
  • The Range.EntireColumn property and Select method are used to choose column B. You can choose a different column by replacing the letter.

Code explanation

  • Click on the Run button.

Running vba macro

  • The results should look like the image given below.

vba columns select single column

Method 2 – Applying VBA Code to Select Multiple Contiguous Columns


  • Open a VBA module (you can follow the previous Method for the steps).
  • Insert the following code:
Sub select_multi_cols()
End Sub

VBA code for selecting multiple columns

Code Breakdown
  • The subroutine’s name is select_multi_cols().
  • The Columns property and Select method will select columns B through D. You can change the range.

Code explanation

  • Hit the F5 key to execute the macro.

Executing vba code

  • Here’s the result.

vba columns select multiple columns

Method 3 – Choosing a Range Using VBA Code


  • Create a new VBA module as shown previously.
  • Insert the following VBA code into the Module.
Sub select_range_of_cols()
End Sub

VBA code for selecting a range of cells

Code Breakdown
  • The subroutine’s name is select_range_of_cols().
  • The Range property and Select method will choose the B6:D9 cells. You can alter this range as you wish.

Code breakdown

  • Hit the Run button.

Clicking run button

  • Here’s the result.

vba columns select a range of cells

How to Select Multiple Columns by Number with VBA Code


Sub select_multi_cols_by_number()
Columns(2).Resize(, 3).EntireColumn.Select
End Sub

VBA code for choosing columns by number

  • Press the Run button or the F5 key.

Pressing F5 key

  • Here’s the result.

vba columns select cells by number

How to Fix the Issue of Selecting Columns with VBA Not Working


  • In this case, Excel returns an error message when we attempt to run the code. We have to use the worksheet name to correctly run the code.

vba columns select returning error

  • Correct the code as shown below.
Sub Fixing_select_col_error()
Worksheets("Columns Select Not Working").Columns("B:D").Select
End Sub

corrected vba code to select columns

  • Click the Run button.

Press run button

  • The required columns are selected as evident in the image below.

fixing vba columns select error

How to Enable the Developer Tab


  • Navigate to the File tab.

Selecting File tab

  • Choose Options from the list.

go to Excel options

  • In the Excel Options window, press Customize Ribbon.
  • Check the Developer tab from the list on the right and click OK.

Tick mark developer tab in the Customize ribbon option

  • The Developer tab appears as shown in the picture below.

Developer tab enabled

Practice Section

We have provided a Practice section on the right side of each sheet so you can practice.

Practice Section

Get FREE Advanced Excel Exercises with Solutions!
Asikul Himel
Asikul Himel

Asikul Islam Himel, holding a BSc in Naval Architecture and Marine Engineering from Bangladesh University of Engineering and Technology, has contributed over two years to the ExcelDemy project. Starting as an Excel & VBA Content Developer, now he manages projects at You Have Got This Math Project. He wrote 60+ articles for ExcelDemy, reviewed 500+, and focused on quality maintenance. Currently, his responsibilities include project management and team leadership. Himel's interests encompass data analysis, leadership, WordPress applications, and... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF