

#How to hide certain columns in excel code#
This is also as easy as the code which we have seen in example #1.

There is another way to hide the column using VBA code. We will see, column A which is at the first position is now hidden. Now, run this code by pressing the F5 key or by clicking on the Play button. If suppose we want to hide the column A using the code of example-1, we just need to place the sequence number instead of selecting it with the help of Range.Ĭolumns(1).EntireColumn.Hidden = True End Sub This process is similar to the code which we have seen in example #1, where we have selected the column name as B and B:C, we will select the sequence number at which the column is located. This process many times don’t get preferred because we can easily get to know the name of the column at which alphabetical location the column is located. Instead of selecting the columns by mentioning the name, we can hide any column by their sequence as well. Here we can see, column B and C are hidden now. Range("B:C").EntireColumn.Hidden = True End Sub Then in the range, we need to select those columns as shown below. If we want to hide more than one column together. We will see, column C is now hidden, now it only shows columns A, B, and D. Now compile the code and run it by clicking on the Play button located below the menu bar in VBA. Range("C:C").EntireColumn.Hidden = True End Sub As we want to hide the selected columns C from the range, so we would select TRUE here. If we choose Hidden as TRUE then, it would as hiding function or if we choose FALSE then it would work as unhiding function. Now, to make this happen, we can choose answer TRUE or FALSE. Here we are hiding column C.Īs we want to hide entire Column C, select the EntireColumn function followed by Hidden as shown below. In the newly opened Module, write the subcategory of VBA Hide Column or we can choose any other name as per our choice as shown below.įirst, select the column/s that we need to hide.
