Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8996151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:42:57+00:00 2026-06-15T23:42:57+00:00

This HideEmptyColumns() macro hides all columns that don’t have any data. How do I

  • 0

This HideEmptyColumns() macro hides all columns that don’t have any data. How do I modify it so that it ignores the header row (row 1)?

Sub HideEmptyColumns()
  Dim Col As Range
  For Each Col In ActiveSheet.UsedRange.Columns
     Col.EntireColumn.Hidden = RangeIsEmpty(Col)
  Next Col
End Sub

Function RangeIsEmpty(R As Range) As Boolean
  Dim Cell As Range
  RangeIsEmpty = True
  For Each Cell In R.Cells
     If Cell.Value <> "" Then
        RangeIsEmpty = False
        Exit For
     End If
  Next Cell
End Function
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T23:42:58+00:00Added an answer on June 15, 2026 at 11:42 pm

    Just check to see what row its on

    Sub HideEmptyColumns()
      Dim Col As Range
      For Each Col In ActiveSheet.UsedRange.Columns
         Col.EntireColumn.Hidden = RangeIsEmpty(Col)
      Next Col
    End Sub
    
    Function RangeIsEmpty(R As Range) As Boolean
      Dim Cell As Range
      RangeIsEmpty = True
      For Each Cell In R.Cells
         'are we not on the first row (header row)
         If Cell.Row <> 1 Then
            If Cell.Value <> "" Then
               RangeIsEmpty = False
               Exit For
            End If
         End If
      Next Cell
    End Function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is C#/.NET 2.0. So I have string that contains the future contents of
This may be an unusual question, but are there any resources people have come
This is the website . I have an strange text display error that it's
This should be a simple one: I have an observableArray object called To in
This code below allows me to find the word error in all my files
This may be a wild strange dream. I dreampt that I could put a
this is the error log i am getting i have highlighted the error also
This is the result I'd like to have: <?xml version=1.0 encoding=utf-8?> <types> <xs:schema xmlns:xs=http://www.w3.org/2001/XMLSchema/>
this is probably the most noob question i have ever asked, i need to
This code compiles and runs though gives a Microsoft compiler error that I cant

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.