Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 465
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,549
Default 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



  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 143
Default 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
  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,522
Default 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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert a variable dependant on content of specific cells Colin Hayes Excel Discussion (Misc queries) 6 February 5th 08 06:06 AM
Selecting range of cells to copy using a variable [email protected] Excel Programming 9 January 26th 08 02:37 PM
Excel Shortcuts - Selecting all cells with the same content G-man Excel Discussion (Misc queries) 2 January 10th 08 06:54 PM
selecting range of cells - variable # of rows [email protected] Excel Programming 6 April 15th 05 02:10 PM
Selecting a variable number of cells in a row Bob C Excel Programming 3 February 2nd 05 12:37 AM


All times are GMT +1. The time now is 11:58 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"