selecting only non empty cells

jchisholm

New Member
Joined
Dec 28, 2009
Messages
5
I have a spread sheet where I want to select from the column only the cells that contain data. The blank cells contain formulas that reference an other worksheet and return a blank when certain conditions are not met. The data returned is the name of an employee and their shift start time. Any suggestions. :)
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Welcome to the Board!

Have you tried AutoFilter? In the Filter criteria just uncheck blanks.

HTH,
 
Upvote 0
Thanks Smitty. The only issue with auto filter is that it affects all of the columns. I have 28 columns, one for each work day in a four week skd. I want to display the whole skd on single sheet with only those employees skd to work that day showing in the column.
 
Last edited:
Upvote 0
Here's a macro you can try (untested) that should select all cells with constants or formulas that don't return a blank ("") value. This is setup for Column A, but is easily adapted to another column:
Code:
Sub SelectNonEmptyCells()
Dim r1 As Range, r2 As Range, r3 As Range
With Range("A:A") 'Change column to suit
    On Error Resume Next
    Set r1 = .SpecialCells(xlCellTypeConstants)
    Set r2 = .SpecialCells(xlCellTypeFormulas)
    On Error GoTo 0
    If Not r2 Is Nothing Then
        For Each c In r2
            If c.Value <> "" Then
                If r3 Is Nothing Then
                    Set r3 = c
                Else
                    Set r3 = Union(c, r3)
                End If
            End If
        Next c
        If Not r1 Is Nothing Then
            If Not r3 Is Nothing Then
                Application.Union(r1, r3).Select
            Else
                r1.Select
            End If
        ElseIf Not r3 Is Nothing Then
            r3.Select
            Exit Sub
        Else
            MsgBox "All cells in the range are empty"
        End If
    Else
        MsgBox "All cells in the range are empty"
    End If
End With
End Sub
 
Upvote 0
JoeMo, thanks for the macro, I ended up recording one to do what I wanted it to do. Without the nudge toward a macro I wouldn't have thought about it.

Thanks again to all poster for the support:beerchug:
 
Upvote 0

Forum statistics

Threads
1,224,617
Messages
6,179,914
Members
452,949
Latest member
beartooth91

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