First Blank Column from L to R

bs0d

Well-known Member
Joined
Dec 29, 2006
Messages
622
I'm looking for an effective way to identify the first blank column (working from left to right).

There could be columns of data with empty columns in between.

For instance:

has data: A, B, C, E, G

blank: D, F, H to End
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Are you talking about the ENTIRE column being Blank?
Or just in 1 specific row?
 
Upvote 0
You could try

Code:
Sub test()
For i = 1 To Columns.Count
    If Cells(1, i).End(xlDown).Row = Rows.Count Then
        MsgBox "The first empty column is: " & Columns(i).Address
        Exit For
    End If
Next i
End Sub
 
Upvote 0
Would it be easier or more efficient code if blank cells in the first row represented the blank column (those that have data, have a value in row 1)?

Maybe

Code:
blankCol = Cells(1, Columns.Count).End(xlToLeft).Column
If blankCol >= 1 Then
blankCol = blankCol + 1
End If

The problem with this is- it detects the first blank column from the right (on the end) and does not identify the first blank between columns that have data (which would be from the left).
 
Last edited:
Upvote 0
Definately easier if a specific row can be used..

Code:
Sub test2()
x = Range("1:1").SpecialCells(xlCellTypeBlanks).Column
MsgBox "The first empty column is: " & Columns(x).Address
End Sub
 
Upvote 0
I've been assuming you're working in VBA..

If you're after a formula, this will give you the column #
Entered with CTRL + SHIFT + ENTER
=MATCH(1,1/(1:1=""),0)
 
Upvote 0
Yes, working in VBA. I had the code from post #5 to find the first blank row on the end, but wanted to see how to find first blank between data. Your VBA code above seems to be working well for me.

I have a query in column "A". Whenever I key in data in column b, c, d, e -- it's applying sort of a filter style to the column and it won't let me clear the contents. So this is screwing things up for me.

How can I keep Excel from applying the auto-filter or whatever it is from the query in column A -- over to the other columns that get data?
 
Last edited:
Upvote 0
Glad that's working for you.
Not sure I understand the new issue.

Probably best to make a new thread on it.
 
Upvote 0

Forum statistics

Threads
1,214,563
Messages
6,120,248
Members
448,952
Latest member
kjurney

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top