Solved

VBA Excel ?  - How do i identify empty columns

Posted on 2000-04-20
4
151 Views
Last Modified: 2011-09-20
I need to figure out what the first column is in spreadsheets that has no data. I think I can remember how to find the last active cell, but what I need is the first column which has no data in any cell in that column.

What is the least brute force method to do this?
0
Comment
Question by:quantz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 17

Accepted Solution

by:
calacuccia earned 50 total points
ID: 2736694
Hi Quantz,

Closely related to your question in Win95 area..

What about the code I posted in that question ?

Sub FindEmptyColumns()
Dim EmptyRange As Range, Col As Range
Set EmptyRange = ActiveSheet.UsedRange.SpecialCells(xlCellTypeBlanks)
For Each Col In ActiveSheet.UsedRange.Columns
If Intersect(Col, EmptyRange).Rows.Count = Col.Rows.Count Then
MsgBox ("Column " & Col.Column & " is empty !")
End If
Next Col
End Sub

To get stop code at first empty column, change to:
Sub FindEmptyColumns()
Dim EmptyRange As Range, Col As Range
Set EmptyRange = ActiveSheet.UsedRange.SpecialCells(xlCellTypeBlanks)
For Each Col In ActiveSheet.UsedRange.Columns
If Intersect(Col, EmptyRange).Rows.Count = Col.Rows.Count Then
MsgBox ("Column " & Col.Column & " is the first empty column in the used range!")
Exit Sub
End If
Next Col
End Sub

Calacuccia
0
 

Author Comment

by:quantz
ID: 2738024
This looked like it would work as is.  But it failed when the text file I "imported" to format had no empty cells in it before the end of the file. It gave me an error message "No empty cells".  So I got rid of the "special cells" part of the code, just selecting "Used Range" and put an integer as a counter in the "For each Col in " loop.  Works fine.
0
 

Author Comment

by:quantz
ID: 2738030
Calacuccia:
Hmm, so thats what happened to my first posting.... ended up in Win5...
Thanks
0
 
LVL 17

Expert Comment

by:calacuccia
ID: 2738134
Here's the URL for your win95 question. I suppose you'll want to delete that one.

http://www1.experts-exchange.com/Computers/Operating_Systems/Windows/Win95/Q_10331770.html

Regarding your problem, you could also use this little modified code (traps the error message 'No empty cells found', displays a little message box and ends the procedure)

Sub FindEmptyColumns()
Dim EmptyRange As Range, Col As Range
On Error GoTo ErrorHandler
Set EmptyRange = ActiveSheet.UsedRange.SpecialCells(xlCellTypeBlanks)
On Error GoTo 0
For Each Col In ActiveSheet.UsedRange.Columns
If Intersect(Col, EmptyRange).Rows.Count = Col.Rows.Count Then
MsgBox ("Column " & Col.Column & " is empty !")
End If
Next Col
ErrorHandler:
MsgBox ("No empty columns in the used range of your spreadsheet !")
End Sub

Cheers
Calacuccia
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
how can i unlock a picture file that was loaded in a picturebox in visual c#? 4 129
vb6 connector to mongodb 2 165
VB6 ListBox Question 4 63
Problem to line 23 81
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question