View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Norman Jones Norman Jones is offline
external usenet poster
 
Posts: 5,302
Default Select Cells In Column that have data

Hi Sean,

How do I select cells in column A that have any type of "Data" in them, it
can be numbers, text, or combination. Just need a macro to autoselect
everything in column A that has data.


Try:

'================
Public Sub PopulatedRange()
Dim WB As Workbook
Dim SH As Worksheet
Dim srcRng As Range
Dim destRng As Range
Dim RngA As Range, RngB As Range
Dim popRng As Range

Set WB = Workbooks("Book1.xls") '<<===== CHANGE
Set SH = WB.Sheets("Sheet1") '<<===== CHANGE
Set srcRng = SH.Range("A:A") '<<===== CHANGE

On Error Resume Next
Set RngA = srcRng.Cells. _
SpecialCells(xlCellTypeConstants)
Set RngB = srcRng.Cells. _
SpecialCells(xlCellTypeFormulas)

If Not RngA Is Nothing Then Set popRng = RngA

If Not RngB Is Nothing Then
If Not popRng Is Nothing Then
Set popRng = Union(RngB, popRng)
Else
Set popRng = RngB
End If
End If

popRng.Select

End Sub
'<<================


---
Regards,
Norman