ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Selecting all cells with content using a variable (https://www.excelbanter.com/excel-discussion-misc-queries/426438-selecting-all-cells-content-using-variable.html)

Colin Hayes

Selecting all cells with content using a variable
 

Hi all

At the end of a macro , I need to select all the cells with content in
the worksheet excluding the first row.

The problem is that the amount of rows and columns to be selected will
vary each time I run the macro.

Sometimes it might need to select for example cells A2:Z270 , or next
time it might need to select cells A2:Y4785 and so on.

Can someone help with some code to select all the cells with content via
variables , whatever the spread , at the end of my macro?

Thanks

Jim Cone[_2_]

Selecting all cells with content using a variable
 
The SpecialCells method will get all data of a particular type...
Set rngStuff = Cells.SpecialCells(xlCellTypeConstants)
-or-
Set rngStuff = Cells.SpecialCells(xlCellTypeFormulas)

Note: xl2010 has problems with SpecialCells on large data areas.
--
Jim Cone
Portland, Oregon USA
http://www.mediafire.com/PrimitiveSoftware
(Data Options add-in: rows/dates/random data & colors)





"Colin Hayes"
wrote in message
...

Hi all

At the end of a macro , I need to select all the cells with content in the worksheet excluding the
first row.

The problem is that the amount of rows and columns to be selected will vary each time I run the
macro.

Sometimes it might need to select for example cells A2:Z270 , or next time it might need to select
cells A2:Y4785 and so on.

Can someone help with some code to select all the cells with content via variables , whatever the
spread , at the end of my macro?

Thanks




James Ravenswood

Selecting all cells with content using a variable
 
How about:

Sub dural()
Dim rSelect As Range, r As Range
Set rSelect = Nothing
For Each r In ActiveSheet.UsedRange
If r.Row = 1 Or IsEmpty(r) Then
Else
If rSelect Is Nothing Then
Set rSelect = r
Else
Set rSelect = Union(r, rSelect)
End If
End If
Next
rSelect.Select
End Sub

Don Guillett[_2_]

Selecting all cells with content using a variable
 
This will select all without the top row

Sub selectem()
ActiveSheet.UsedRange.Offset(1).Select
'or
'ActiveSheet.UsedRange.Offset(1).clear
End Sub



On Friday, March 2, 2012 8:02:41 PM UTC-6, Colin Hayes wrote:
Hi all

At the end of a macro , I need to select all the cells with content in
the worksheet excluding the first row.

The problem is that the amount of rows and columns to be selected will
vary each time I run the macro.

Sometimes it might need to select for example cells A2:Z270 , or next
time it might need to select cells A2:Y4785 and so on.

Can someone help with some code to select all the cells with content via
variables , whatever the spread , at the end of my macro?

Thanks



All times are GMT +1. The time now is 06:53 PM.

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