
- #HOW DO I HIDE COLUMNS IN EXCEL SPREADSHEET HOW TO#
- #HOW DO I HIDE COLUMNS IN EXCEL SPREADSHEET CODE#
In other words, we want to hide the names of the male employees when that happens. Similarly, we want only the female employee names to be displayed when cell E2 contains the value “F”. In other words, we want to hide the names of female employees. We want only the male employee names to be displayed when cell E2 contains the value “M”. In the above dataset, we have a list of male and female employee names in two separate columns (A and B). In this example, we have the following dataset: So, let’s now take a look at another example that demonstrates this. However, most of the time, we want to hide columns on-the-fly, based on the value in a particular cell. In the first example, the columns are hidden only when the macro runs. Hiding Columns in Real-time Based on a Cell Value You can run this macro in exactly the same way as HideCols. In other words, we set the ‘Hidden’ attribute for the column to False, because we want Excel to unhide (or display) the corresponding columns containing an ‘X’ in row 8. Notice all we did is change line 5 from: = True

#HOW DO I HIDE COLUMNS IN EXCEL SPREADSHEET CODE#
Copy and paste the following code into it: Sub UnhideCols() Repeat the same steps as above to create a new macro. All you need to do is make a small change to the HideCols function. Now what do we do if we want to see the hidden rows again? Un-hiding Columns Based on Cell Value when Macro is Executed In this way, the above code hides all the columns containing an ‘X’ in row 8.


It should essentially analyze each cell from A8 to F8 and adjust the ‘Hidden’ attribute of the column that you want to hide. Say you have columns containing sales figures for Monday through Friday, and you want to run a macro to hide all columns that have the letter X in row 8.įor this, we need a macro that will loop through each cell of row 8 and hide the corresponding column. Let us use the following dataset to demonstrate: It can be a number, a letter, a word, or even a phrase. The value, based on which you want to hide the columns, can be anything you like.
#HOW DO I HIDE COLUMNS IN EXCEL SPREADSHEET HOW TO#
In this example, we will show you how to hide all columns that contain a particular value in a given cell. Hiding Columns Based on Cell Value when Macro is Executed
