Both the Excel formula and VBA approach make use of the COLUMNS function to count the number of columns in a selected range. Using the VBA method you will also need to combine the Columns function with the Count function to return the total number of columns in a selected range.

The COLUMNS function, after specifying an Excel range, will return the number of columns that are contained within that range. The COLUMNS Function in Excel is an Excel Lookup/Reference function. It is useful for looking up and providing the number of columns in a given reference or array.