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 6581791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:11:55+00:00 2026-05-25T16:11:55+00:00

I want to supply a number (ie. 4 which represents the 4th column –

  • 0

I want to supply a number (ie. 4 which represents the 4th column – D) and then have a msgbox return the number of non blanks in that column

For example below there are 5 blanks in column D:

col A     col B      col C     col D     col E
------   -------     ----     -------    ------
                               gh


                               2h



                               34 

code so far:

Sub Tester()
CountBlanks 4
End Sub

Sub CountBlanks(ByVal colNum)
columnLetter = ??
columnCount = ??
MsgBox "Count of column: " & columnLetter & " is " & columnCount 
End Sub

Expected result:

"Count of column: D is 5" 
  • 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-05-25T16:11:55+00:00Added an answer on May 25, 2026 at 4:11 pm

    The answer depends on what you actually want to count:

    1. All blank cells in a column with respect to the entire table.
    2. All blank cells up to the last used cell within the specific column itself.

    Most people are trying to achieve the first option which is a little tricky.
    For counting blanks the specialcells function is the way to go. However as specialcells uses the sheets usedrange it can become unreliable as excel is known to keep track of the usedrange badly. So first we must call the usedrange function to reset it.

    Function CountBlanks(colNum As Long)    
        Dim sColumn As String
        Dim lBlanks As Long
    
        sColumn = Split(Columns(colNum).Address(ColumnAbsolute:=False), ":")(0)    
    
        ActiveSheet.UsedRange
        lBlanks = ActiveSheet.Columns(colNum).SpecialCells(xlCellTypeBlanks).Count
    
        MsgBox "Count of column: " & sColumn & " is " & lBlanks
    End Function
    

    If you were after option 2 then it is just a case of getting the last cell in the column and counting with specialcells.

    Function CountBlanks(colNum As Long)    
        Dim sColumn As String
        Dim lBlanks As Long
    
        sColumn = Split(Columns(colNum).Address(ColumnAbsolute:=False), ":")(0)    
    
        lBlanks = Range(Cells(1, colNum), Cells(Rows.Count, colNum).End(xlUp)).SpecialCells(xlCellTypeBlanks).Count        
    
        MsgBox "Count of column: " & sColumn & " is " & lBlanks
    End Function
    

    EDIT

    Jmax, the code is actually correct. The call to reset the used range has to be on its own. On the next line when calling specialcells you don’t need to specify usedrange.

    Its hard to explain but try this:
    Comment out the ActiveSheet.UsedRange line. With your test data add a value to a cell further down the page from the table and run the code. It will return the count of blanks up to this newly added cell. Now delete the entire row of the cell you added and re-run the code. It will still return the same count because excel has not reset its inbuilt counter. Now uncomment the line Activesheet.Usedrange, run the code and you will get the correct result.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want a function that can take a number (say 1000.43) and return the
I want to supply a number, and then receive a set of random numbers.
Our Client requires that we supply Widgits for their site. They want to link
want to have a Hyperlink-Button in a gridView in which I can display a
I have a function with the name MakeInitialCapital. I want to supply control name
We have a number of NHibernate Entities that map to data that is specifically
I'm trying to get column names from a table. I want to supply the
I have a big load of documents, text-files, that I want to search for
I want to supply unknown object and return the value of one of its
Want to run javascript function from parent window in child window Example I have

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.