This article will guide you step-by-step through the process of selecting specific columns in Excel, such as every other or every nth column.
Microsoft Excel, the go-to spreadsheet software for data enthusiasts and professionals, offers several methods to select columns based on specific criteria. While many are familiar with the standard techniques, there exist lesser known but more efficient variations to accomplish this task.
Select alternate columns in Excel
The simplest way to select alternate columns in Excel is by utilizing the Ctrl key in combination with the mouse. Here's how you can do it:
- Press and hold the Ctrl key on your keyboard.
- While holding the Ctrl key, click on the header of every other column.
- Repeat steps 2 and 3 until you have selected all the desired columns.
- Release the Ctrl key.
As a result, you have the alternate columns selected:
By using the Ctrl key, you can handpick every 3rd, every 4th or every nth column, so you can apply formatting or perform calculations on specific sections of your data.
This method of selecting every other or every nth column is a straightforward and effective approach, particularly for small datasets. However, it may become cumbersome and time-consuming when dealing with large sets of data. Manually clicking on each column header can be prone to errors and can become tiresome. In such cases, alternative methods come in handy to streamline the process and save valuable time.
Selecting every other or nth column with formula
If you prefer a more precise method to select every other or nth column in Excel, you can achieve this by using the CHOOSECOLS function. Here's how you can use it:
- In an empty cell, enter the CHOOSECOLS formula. The first argument should be the source range that contains the columns you want to select.
- In the subsequent arguments, provide the column numbers you want to return.
- Press Enter to apply the formula.
For example, to select every even column in the range A2:F20, the formula takes this form:
=CHOOSECOLS(A2:F20, 2, 4, 6)
This formula specifies that you want to return columns 2, 4, and 6 from the range A2:F20.
The CHOOSECOLS formula returns the specified columns as a dynamic array, which you to easily select and copy to another part of your worksheet.
Excel VBA to select every other column
Using VBA macros in Excel, you can automate the process of selecting every other column with precision and efficiency.
Macro to select every odd column in Excel
This VBA code enables the selection of every odd column in Excel such as 1, 3, 5, etc. It achieves this by iterating through the columns within the user-selected range and creating a new range that includes only the odd columns. The resulting range is then selected, allowing for easy identification and manipulation of the desired columns.
Macro to select every even column in Excel
The following VBA code allows selecting every even column such as 2, 4, 6, etc. It automates the process by iterating through the columns within the pre-selected range and creating a new range that includes only the even columns.
To add the codes to your workbook, follow the steps described in How to insert VBA code in Excel.
To select every other column using a macro, follow these steps:
- Highlight the range in which you want to select columns.
- Press Alt + F8 to open the macro dialog box.
- Choose the desired macro - SelectOddColumns or SelectEvenColumns.
- Click Run to execute the code.
Excel macro to select every Nth column
If your task is to select every Nth column within a range, you can accomplish it using a VBA macro and a UserForm.
First, create the UserForm:
- In the VBA Editor, click Insert > UserForm.
- Design the UserForm with an input field such as a TextBox to enter the value for N.
- Add an OK button to trigger the macro.
After completing the form's design, add the code for the OK button. For this, double-click the OK button on the UserForm and paste the following code in the Code window:
Finally, create the SelectEveryNColumn macro to incorporate the UserForm and complete the functionality. For this, add the following code to the module in your workbook:
Tip. To save time, you can download our sample workbook at the end of this post, which includes the pre-designed UserForm and the macro. And then, just copy the code and UserForm1 from the sample workbook into your own one.
Once implemented, running the macro will display a pop-up dialog box asking for the value of N. Enter the desired number, and the macro will select every Nth column within the selected range.
As you see, Excel offers a diverse range of methods to select alternate columns or every other column. Whether you prefer the commonly known Ctrl key technique, where you manually handpick the desired columns, or the ingenious use of the CHOOSECOLS formula, or the automated solutions with VBA macros, Excel has you covered. The choice ultimately depends on your preferences, the complexity of your dataset, and the level of automation you seek. So, explore these options, experiment with different techniques, and find the approach that best fits your needs. Happy column selecting!
Practice workbook for download
VBA to select every other or every Nth column in Excel (.xlsm file)
3 comments
We can use =SEQUENCE(,3,2,2) in the place of {2,4,6} to make more efficient.
Hello! Thanks for the great guidance. I was wondering how would the code change if I want to select every odd columns for a specific range of rows, for example, I want every odd columns of row 1-5?
Hi! Highlight the range of values in rows 1-5 and use the macro recommended above. Do not highlight entire rows as this will slow down your computer and makes no sense.