Email:      Pass:    Pass?
Close Window   
Free Ebook
Get Your Free Excel
Our Top 15 Excel Tutorials
Instant Access!

Subscribe for Free Excel tips & more!

Free Excel Forum

Vba Macro To Hide Certain Columns

Forum Register
Search Excel Forum Posts, Tutorials, Macros, Tips, and More


I would like to use a VBA Code to hide columns that fall under a certain criteria. For example, lets assume I have several columns of data with a "total" cell under each column that sums the numbers. What I would like to do is hit a macro button that will automatically hide any column that has a sum less than a certain number. This would have to be dynamic meaning we would have to type a number into a cell in excel; for example if I wanted to hide all columns that have a sum less than 5%, I would like to enter 5% into a cell, hit a macro, and then have it go through and hide the columns.

Hope this isnt too confusing. Let me know if you need more clarification.


View Answers     

Similar Excel Tutorials

Hide Data Within a Worksheet in Excel
In Excel you can actually hide data that is stored within a worksheet. This allows you to show data that is useful ...
Hide or Unhide a Worksheet by Hand in Excel
I'll show you how to hide worksheets in Excel so that a user cannot see them but you can still access data on them ...
Completely Hide the Ribbon Menu in Excel
I'll show you how to completely remove the entire Ribbon Menu from Excel. This will allow you to have a streamline ...
Run a Macro from Another Macro in Excel
I will show you how to run a macro from another macro in Excel.  This means that you can run any macro when you ne ...

Helpful Excel Macros

Filter Data Sets on Multiple Columns with Multiple Criteria at Once in Excel - AutoFilter
- This Excel macro allows you to filter a data set on multiple columns and criteria at once. This means that you can filt
Hide Specific Comments in Excel - Comments Will Still Display on Hover
- Hide specific comments in Excel with this macro. Comments are still visible on hovering over the cell that contains the
Hide Comments in Excel Completely - Even Indicators Will not Appear
- Hide all comments in an Excel workbook. No indicators will be displayed and comments will not appear when you hover ove
Reverse Row or Column Order in a Worksheet
- This macro reverses the order of a selected row or column in excel. It will completely reverse the data.
Hide Comments in Excel Partially - Comment Indicator Shows and Will Display on Hover
- Hide comments in Excel with this macro. Comment indicators will still appear in the cells and users will also be able to

Similar Topics

I'm trying to write a Macro that will hide columns based on a user input, and then rows based on what is left over.

Basically, when the workbook is opened, I want a box to pop up that says enter store number. Then the store number is typed, and OK is pressed, and it will hide all columns in the range Z:IV that do not have that store number in row 1. There will only and always be one column that will remain unhidden.

After that is done, I want to hide all rows in the range 2:2000 that have a blank or 0 value in that column that was NOT hidden in the above step. This column will be dynamic though.

IE: If you enter store "101" in, all columns right of Y will hide except column AA (just an example), which contains "101" in cell AA2. Then all rows that are blank or have a value of 0 in column AA will be hidden.

Then if you enter store "202" in, all columns right of column Y will hide except column BA this time, which contains "202" in cell BA2. Then all rows that are blank or have a value of 0 in column BA will be hidden as well.

I would like this to all happen in one macro. So when the store # is entered, everything is done and ready to view.

I know this is probably difficult, but if it makes it much easier, I guess I could deal with deleting rows and columns instead of hiding. I would much rather hide, but if deleting is the only way, it is acceptable.

Thanks in advance.

Hi there... i hope that some kind soul will be able to help me in this.

I have a spreadsheet with about 200 columns and i need a macro to hide most of them. The column headers that i do not want to hide in the data tab is listed in a separate worksheet in column A.

The macro will read from column A, look in the data sheet header and hide those columns that are not in the list.

I also need a separate button to un hide all of them.

Thanks in advance guys!

I have excel sheet which has A to D Columns as text coulmns. E to IV are data columns. I need to create hide and unhide buttons so that :
Clicking on HIDE, hides 7 columns starting from E. When user clicks on HIDE again it should hide next 7 columns and so on as so forth. Clicking on UNHIDE button should unhide last 7 hidden columns and so on and so forth. e.g. A user clicks on HIDE button once, 7 columns from E should hide, next click on HIDE should hide next 7 columns from L, next click on HIDE should hide next 7 columns from S. Now user clicks on UNHIDE button, it should unhide last hidden columns i.e. show all columns until S.

Any help is greatly appreciated.


Hello all,

I am using Excel 2007 in Windows 7. My issue is that I need columns to automatically hide themselves without having to Alt+F8 and running the program. My data set is:

A B C D E F 1 1981 1982 1983 1984 1985 1986 2 4 2 1 3 6 3 3 5 3 2 7 9 4 4 6 5 2 5 6 6
If the value in Row 1 equals 0, I want that entire column to automatically hide itself. So if D1 = 0, then Column D would automatically hide itself. Any suggestions?

Hi -

Could someone please show me a better way to hide all columns with zero value in my excel 2003 file? It would be great that i could have a macro embed in my workbook/sheet that automatically hide all these zero value columns and only show the ones with valid values. Currently, i have to mananually select all columns with zero value and hide them one by one. This takes so much time since i have more than 6-7k rows. Thanks!


Hello Everyone,

I am trying to figure out a macro (or formula if one exists) to hide/unhide columns in my excel worksheet based on the cell value in the first row of the column. Based on how my sheet is set up, this is my desired result:

If cell C1:=0, then Hide Column C. If not, unhide column C
If cell D1:=0, then Hide Column D. If not, unhide column D
If cell E1:=0, then Hide Column E. If not, unhide column E
If cell F1:=0, then Hide Column F. If not, unhide column F
If cell G1:=0, then Hide Column G. If not, unhide column G
If cell H1:=0, then Hide Column H. If not, unhide column H
If cell I1:=0, then Hide Column I. If not, unhide column I

See attached sample workbook for the set up. I must say that I am relatively new to using excel macros and programming in excel. Any detail you all can provide would be very helpful. Thanks in advance. Regards,


Hi everyone,

Im hoping someone who is experienced with Macros can help me by providing a code that can hide Columns by their Titles...I am working with a shared document, i need the codes for a few Macros (these would be prompted by a button I can create) that will Hide specific Columns, but i would need these to be hidden by the Titles listed in Row 1...the reason being is that new columns will be added by other users in the future...

so for example,
Macro 1 would need to hide all columns Except for "Generic 1" "Generic 2" "Generic 3" and "Jim"
Macro 2 would need to hide all columns Except for "Generic 5" and "Wire"
Macro 3 would need to hide all columns Except for "Generic 2" Generic 6" Generic 7" "Generic 8" and "Mach"

I hope that there is a code i could use to do this,

I have an excel worksheet that has filters on Columns B:G. What I want to do is set macros in the workbook that will hide certain columns based on any filters that are set.

For example, if a user were to set a filter on Column B, Columns C:G would hide. If a user were to set a filter on Column C, Columns B and D:G would hide. This would go on through the end of the columns that have filters on them.

Then I would also want a macro to unhide all columns, in the event one wanted to see everything.

Thanks for any help you all can give!!

I have 300 plus coulmns. I want to hide about 80 of the columns. I know the columns to hide in two different ways.
1. I could hide every third column.
2. I could hide every column that contains a row that has the text "atot".

I would like to use a macro to do this, Excel might call it something other than a macro. I use a produce called Macro Express that could do this. I would like to use whats avaible in Excel to do this. I'm using 2007.

Every time I find myself doing 100's of mouseclicks I reach out to you guys for help . . .taking a long shot here . . .
I have a worksheet with 40 columns of data; 20 or more of which the client doesn't need to see (they get confused easily). But we send this sheet back and forth. So I have to unhide all columns, do my thing, then hide them again . . . Here is what I was thinking . .
If I format the column headers in yellow, for example, for the columns the client needs, and Blue for the columns they don't need, is there a way to automatically hide columns for the columns with a Blue header cell?

I can do the macro to automatically unhide all cells, but want to be able to quickly re-hide them.


I have little knowledge of VBA so tried to record a macro that I can then assign to a button in order to hide certain columns of a worksheet.

The worksheet contains data on all members of staff. I want to script three buttons to display data for Department 1, Department 2 and All. On click, I want it to hide the columns irrelevant to that department but it seems to not want to do individuals, but all of them within that range.

For example, hide columns B, C, F, and H.

I've recorded the macro but upon replaying it (or using the code generated for the button) it hides all columns up to H.

Any ideas ladies and gents? As always, very grateful for any ideas!

I have 10 rows of data. Is it possible to have some macro that says 'if in row A, any of the cells contain "1", then show columns B&C. If all of those 10 cells in column A contain anything other than "1", then hide columns B&C'. Default should be that B&C are hidden.

This needs to be real-time. I.e. As soon as I enter "1" in those cells, columns B&C need to immediately un-hide.

I am terrible with macros so any specific code would be gratefully received.

The other day I had posted a thread asking if anyone could help me ensure certain columns were hidden when a .xls was opened.


Now Id like to be able to hide the columns only if row B of the colum contains the text "hide me". Please not the cell may contain other text, such as "Q1, hide me"

Anyone know if its possible?

eg I want to hide Cols B and D

1 A B C D 2 Shop items 3 date Q1, hide me Item Supplier, hide me 4 01/01/2006 q1 2006 Juice Pepsi 5 05/01/2008 q1 2008 crisps walkers

I am trying to figure out a way to hide columns based upon how many columns are in use. For example, I have multiple motor types in A1:A15 and information about them in B:N.
Columns O and on contain information I gather upon inspection (Right now I have info in Columns O:Z).

So, what I want to do is create some kind of formula that states if columns O:forever have information hide all these rows EXCEPT the last four. For my example above (info in columns O:Z) I would want this to hide columns O:V. If I where to add another column (now O:AA) i would want it to know that it now needs to hide O:W automatically.

If this isn't clear please let me know and I will try to be more specific.

I'm not sure if this is possible, but would appreciate any suggestions.


OS - Windows XP
Excel 2003

I am somewhat a novice with VBA, in other words, I am still learning. I am trying to write a vba macro that would hide columns based on what is presented in another table. This will allow me to update the table and not have to worry about updating the macro on a continuing basis.

For example.

A1: Football
B1: Basketball
C1: Baseball
D1: Hockey - HIDE
E1: Soccer - HIDE

Table Hide:


Would you suggest creating an if statement that would assign anything in the table to be equal to = X.
Therefore, writing the code to hide columns in A1:E1 = X.

Thank you in advance,
~ Jason

Hi. Something goofy is going on, and I was wondering whether or not someone might have a helpful tip...

I used Macro Recorder to create a macro which would effectively, upon clicking a Forms button, hide 6 columns in my worksheet. I activated Macro Recorder, CTRL-clicked the six columns that I wanted to hide, went to "Format -> Columns -> Hide", and the six columns were hidden. I then stopped the recording. What Macro Recorder generated was this:


Sub HideGBWEntries()
' HideGBWEntries Macro
' Hides GBW Entry Columns
' Keyboard Shortcut: Ctrl+g
    Selection.EntireColumn.Hidden = True
End Sub

For some reason, when I run this macro, it hides columns C through Y!!

I do have some conditional formatting and formulas applied to some cells in the in-between, but I cannot, for the life of me, figure out why it hides all those columns.

I know it must sound like I don't have a clue what I'm doing, but what I'm reporting here is, in fact, what is happening, and I'm baffled.

Any ideas? Thanks!!

I love this place. The more questions I have answers, the more dependent I become because the more I realize is possible, that I can't do.

This time, I'm trying to hide columns based on values on certain cell values.

Here's the macro I'm using...

Sub HideEmptyColumns()
 Dim cell     As Range
  For Each cell In ActiveSheet.Range("AL155:EZ155")
    If cell.End(xlDown).Row = Rows.Count Then
    cell.EntireColumn.Hidden = True
    End If
 Next cell
End Sub

I WANT the macro to look at cells and if the cell is empty hide the column...
If AL155 is empty, hide Column AL
If EZ155 is empty, hide Column EZ

When I run this macro though, it just hides all columns from AL to EZ.

Do I have to create new macros for each column? or is it possible with a single macro?

Thanks again guys!


I'm trying to protect/hide the formulas on a w/s by protecting the w/s so that I may not accidentally delete or overwrite them.
It works fine with the exception that the Hide & Unhide column no longer available either via Format::Column::Hide and Unhide or by a macro.

The macro to hide / unhide columns produces:
Run-time error '1004':
"Unable to set the Hidden property of the Range class"
and in the macro code:
...>Selection.EntireColumn.Hidden = True
is highlighted

Is there a workaround this difficulty; namely protecting the w/s formulas and still be able to Hide / Unhide columns ??

Thank you kindly.

In row 7 of Columns G thru R (12 columns) of a worksheet called "output", I have dates for January 31st thru Dec 31st (in a given year). Based on an input cell that contains one of these 12 dates, I want to hide all columns (in that year) that are on or before that date. So, I could start with column G and hide it as well as up to 11 more columns immediately to its right. Example, if the input date were 7/31, I would want to hide the first seven columns and keep the last five. I guess column G would always be hidden with this algorithm.

Can anyone help me with the syntax of such a macro? Thank you very much!

Also, somewhere on the web, I seem to recall a site with loads of examples of EXCEL macros for doing common things. Often I can figure out how to adapt one of these. Can anyone help me to rediscover it?


I have 30 columns that the user could hide if they wished. Different users will need to look at different columns so the option to hide and unhide columns is needed.

I have written this code below to hide and unhide a column when a check box is checked on a user form. Ideally I would like it to work from a command button.

Is there a better way I could write this code to hide certain columns. Lets say columns A,C,D,F,G,I,M,P

Or will I have to write this for each column and checkbox

Private Sub CheckBox1_Click()
If CheckBox1.Value = False Then
Sheet1.Columns("A").EntireColumn.Hidden = True
If CheckBox1.Value = True Then
Sheet1.Columns("A").EntireColumn.Hidden = False
End If
End If
End Sub


I have a sheet with 2 years of data
Columns B-M have Jan-Dec data for 2010 and N-Y have 2011.

When we are sending out the sheet we only want to show the current month and the previous years month.

So for Januarys version we would hide C-M and O-Y
In feb we would hide B and D-M and O and Q-Y and so on and so on...

I need a vba way of doing this as I have a preperation macro which applies all last min formatting and cleanup (removal of links etc) and this is the last issue I cant really resolved without going into the macro each month to fix it.

The reporting month we are in is in a cell in a sheet say A1 in sheet X, so the macro would need to read the date to understand what columns to hide.

Any ideas?


I have a Jet Report that I created which works great. After the report is created, it auto-hides any column or row that has a jet function in it to make the report easier to read. What i am trying to do is delete any column or row that has HIDE at the beginning. example below-

1 hide hide hide hide hide
2 hide
4 hide

After the report is saved, Columns ABCEF are hidden, but still there, i don't need this data any longer and would like to remove it from the document without affecting the original excel document.

any suggestions?

Hi All,

I need to be able to hide columns (6 columns, they all have info i need to hide) if a value in another part of that same column = Current (the word current).

So N11 = Current, when I run the macro it should hide Col N-S. Also, if Z11 = Current, when I run the macro it should hide Col Z-AE etc etc for All columns where row 11 = Current. Each section that I need to hide has 6 columns associated with it.


Sorry for posting this - I have been trawling the internet for the past day or so and just cannot seem to find anything that is suitable (I am an accountant and not completely conversant with macros).

I would like to hide columns when criteria in a column range is met...

Example, I would like to look at the range G73:DA81 and hide the column if the formulae is <=0. In other words, if range G73:G81 <=0, then hide column G, similarly H73:H81 <=0, then hide column H.....I, J, K etc.

Can you also provide me with the details to unhide them?

Many thanks

I am trying to hide columns. I have created two variables that store the column number. For example if I wanted to hide columns E through G then I have begin_group = 5 and end_group = 7. I am now trying to figure out, how do I select this column range to hide. I tried:


Something in my columns() is not right, but I don't know how to do the selection.

Any help would be great.