Results 1 to 5 of 5

Thread: [RESOLVED] Delete hidden columns

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2005
    Posts
    61

    Resolved [RESOLVED] Delete hidden columns

    I have made a macro that moves information from one sheet to another, but when there are hidden columns it distorts the results. I would like to add code to my macro that will delete the hidden columns.
    Last edited by Botillier; Sep 1st, 2005 at 01:14 PM.

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Delete hidden columns

    Post your current code.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Member
    Join Date
    Aug 2005
    Posts
    61

    Re: Delete hidden columns

    The deleting of hidden columns would be one of the first procedures in this particular macro. I have a feeling that the appropriate code would be to select the appropriate range, loop through the selected columns, use a true/false statement to determine whether the column is hidden or not, if it isn't hidden than I would skip it, but if it is I would delete it. So far the only education that I have received on loops and if/then statements has been from this forum, I am still very new at this and don't know how to correctly use these tools.

  4. #4

    Thread Starter
    Member
    Join Date
    Aug 2005
    Posts
    61

    Re: Delete hidden columns

    I found the below code at: 'http://www.sowsoft.com/excel-macros.htm
    I think that it is sort of what I am looking for except it deletes rows instead of columns, as well as, searches all worksheets. My macro will be used with the appropriate worksheet showing so I will not have to loop through all of the worksheets. I have played with this for a while without luck.
    VB Code:
    1. For i = 1 To Worksheets.Count
    2.   If Worksheets(i).Visible Then
    3.     Worksheets(i).Select
    4.     ActiveCell.SpecialCells(xlLastCell).Select
    5.     k = ActiveCell.Row
    6.     For j = 1 To k
    7.       If Rows(j).Hidden Then
    8.         Rows(j).Hidden = False
    9.         Rows(j).Delete
    10.       End If
    11.     Next j
    12.   End If
    13. Next i
    14. If Worksheets(1).Visible Then Worksheets(1).Select

  5. #5
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    Re: Delete hidden columns

    Try this version instead
    VB Code:
    1. Dim lstcol As Integer
    2.   lstcol = ActiveCell.SpecialCells(xlCellTypeLastCell).Column
    3.   Dim i As Integer
    4.   For i = lstcol To 1 Step -1
    5.     If Cells(1, i).EntireColumn.Hidden Then
    6.       Cells(1, i).EntireColumn.Delete
    7.     End If
    8.   Next i
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width