I opened your file in Excel 2010 and ran your macro.All columns that had at least one "X" in it was displayed.Your column "K" has an "X" in row 4, so I'm not sure why you think it should've been hidden. There's a couple of things in the macro that I'd change:1) When you're looking through the values in the column, I'd follow the suggestion: "When you find what you're looking for, stop looking". That is, when the cell value is non-blank, set your flag and then use: Exit For so that you break out of the loop (for the column) This isn't a big deal when you're dealing with 25 columns and only 7 rows. Since that is "only" 175 if() tests.but if you're working with 67 rows, that's a WHOLE lot more.And in your example, 11 of the 25 rows will stop after the first test,(since there's a value in the first record) If your macro is failing to hide column "L",I'd add a line in the macro: For i = 1 To nLastColumn If (i = 12) Then Debug.Assert False this will cause the macro to "pause" at the start of evaluating column L and you can step through the macro to see where it's finding a value that causes it to fail to hide. I'll take a look again after my 7:30 meeting! :)
Paul----------------------------------------- “Do all the good you can, By all the means you can, In all the ways you can, In all the places you can, At all the times you can, To all the people you can, As long as ever you can.” - John Wesley ----------------------------------------- From: Becky Strope <rstrope...@gmail.com> To: MS EXCEL AND VBA MACROS <excel-macros@googlegroups.com> Sent: Tuesday, July 28, 2015 4:31 PM Subject: $$Excel-Macros$$ Hiding empty columns using VBA - Some columns not hiding I've got several Excel files that I'm trying to clean up on a regular basis, part of which includes hiding columns (with column headers) that don't contain any data. All of the columns I'm looking to hide have If Statements linked to information in other cells. In poking around for workable code, I found this post -- https://groups.google.com/forum/#!topic/excel-macros/abziBlIHT7I -- and am using that code. It works partially. Most columns are being hidden, but there are four columns (K, L, M, and O) that should be hidden but don't. I'm not sure why it's not working completely. Any help would be appreciated. -- Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s =TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @ https://www.facebook.com/discussexcel FORUM RULES 1) Use concise, accurate thread titles. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get quick attention or may not be answered. 2) Don't post a question in the thread of another member. 3) Don't post questions regarding breaking or bypassing any security measure. 4) Acknowledge the responses you receive, good or bad. 5) Jobs posting is not allowed. 6) Sharing copyrighted material and their links is not allowed. NOTE : Don't ever post confidential data in a workbook. Forum owners and members are not responsible for any loss. --- You received this message because you are subscribed to the Google Groups "MS EXCEL AND VBA MACROS" group. To unsubscribe from this group and stop receiving emails from it, send an email to excel-macros+unsubscr...@googlegroups.com. To post to this group, send email to excel-macros@googlegroups.com. Visit this group at http://groups.google.com/group/excel-macros. For more options, visit https://groups.google.com/d/optout. -- Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s =TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @ https://www.facebook.com/discussexcel FORUM RULES 1) Use concise, accurate thread titles. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get quick attention or may not be answered. 2) Don't post a question in the thread of another member. 3) Don't post questions regarding breaking or bypassing any security measure. 4) Acknowledge the responses you receive, good or bad. 5) Jobs posting is not allowed. 6) Sharing copyrighted material and their links is not allowed. NOTE : Don't ever post confidential data in a workbook. Forum owners and members are not responsible for any loss. --- You received this message because you are subscribed to the Google Groups "MS EXCEL AND VBA MACROS" group. To unsubscribe from this group and stop receiving emails from it, send an email to excel-macros+unsubscr...@googlegroups.com. To post to this group, send email to excel-macros@googlegroups.com. Visit this group at http://groups.google.com/group/excel-macros. For more options, visit https://groups.google.com/d/optout.