ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Select Cells In Column that have data (https://www.excelbanter.com/excel-programming/361501-select-cells-column-have-data.html)

Sean[_15_]

Select Cells In Column that have data
 
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.

Thanks

Sean

[email protected]

Select Cells In Column that have data
 
You can record it - the actions are
data menu, filter, autofilter
filter on column a to Non Blanks

stop the recorder - macro done!


[email protected]

Select Cells In Column that have data
 
Hi
Range("A:A").SpecialCells(xlCellTypeConstants, xlNumbers +
xlTextValues).Select

Will select cells with text or numbers. If you want formulas change to
xlTypeFormulas in specialcells. If you want constants and formulas, you
will have to do a set statement

Set ConstCells = Range("A:A").SpecialCells(xlCellTypeConstants,
xlNumbers + xlTextValues)

and same for FormulaCells. Then union the two ranges and select that.

regards
Paul


Norman Jones

Select Cells In Column that have data
 


--
---
Regards,
Norman



"Sean" wrote in message
...
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.

Thanks

Sean




Norman Jones

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




All times are GMT +1. The time now is 08:48 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com