Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8
Default Selecting all cells using macro

I need to be able to select a range of cells from the first (A1) to the last
active cell. I know there is a Go To.... / Special Cells option but I need a
statement to do this that I can use in a macro. If possible I would like to
give this a name (eg-"All_Active_Cells" so that I can reference it easily in
the macro.
Thanks
Robert
  #2   Report Post  
Posted to microsoft.public.excel.misc
D. D. is offline
external usenet poster
 
Posts: 53
Default Selecting all cells using macro

something like this??

Range("A1").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default Selecting all cells using macro

You could employ the usedrange selection.

Sub select_range()
''good if used range has been previously reset
Dim someCells As Range
With ActiveSheet.UsedRange
Range("A1").Select
Set someCells = ActiveSheet.Range(ActiveCell, _
.Cells(.Cells.Count))
End With
someCells.Select
End Sub

But Excel has a habit of over-estimating the usedrange so another method can be
employed to circumvent that over-estimation.

Add this UDF to your workbook.

Function RangeToUse(anySheet As Worksheet) As Range

'Bob Flanagan construct.
'this function returns the range from cells A1 to cell which is the
'intersection of the last row with an entry and the last column with an entry.
'used with UsedRangePick macro.....REAL USED RANGE!!

Dim i As Integer, C As Integer, r As Integer
With anySheet.UsedRange
i = .Cells(.Cells.Count).Column + 1
For C = i To 1 Step -1
If Application.CountA(anySheet.Columns(C)) 0 _
Then Exit For
Next
i = .Cells(.Cells.Count).Row + 1
For r = i To 1 Step -1
If Application.CountA(anySheet.Rows(r)) 0 Then _
Exit For
Next
End With
With anySheet
Set RangeToUse = .Range(.Cells(1, 1), .Cells(r, C))
End With
End Function

Then use this macro.

Sub UsedRangePick()
Dim tempRange As Range
Set tempRange = RangeToUse(ActiveSheet)
tempRange.Select
End Sub


Gord Dibben MS Excel MVP

On Sat, 7 Oct 2006 14:03:02 -0700, robertlewis
wrote:

I need to be able to select a range of cells from the first (A1) to the last
active cell. I know there is a Go To.... / Special Cells option but I need a
statement to do this that I can use in a macro. If possible I would like to
give this a name (eg-"All_Active_Cells" so that I can reference it easily in
the macro.
Thanks
Robert


  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 10,124
Default Selecting all cells using macro

Sub setnamerange()
'last row in col A
lr = Cells(Rows.Count, "a").End(xlUp).Row

Set myrng = Range(Cells(1, "a"), Cells(lr, "a"))
myrng.copy 'Select
End Sub

--
Don Guillett
SalesAid Software

"robertlewis" wrote in message
...
I need to be able to select a range of cells from the first (A1) to the
last
active cell. I know there is a Go To.... / Special Cells option but I need
a
statement to do this that I can use in a macro. If possible I would like
to
give this a name (eg-"All_Active_Cells" so that I can reference it easily
in
the macro.
Thanks
Robert



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
How to use macro to edit data in Excel cells Annamalai Excel Discussion (Misc queries) 11 September 21st 06 07:44 AM
selecting cells which contain formulas but return blanks hot dogs Excel Discussion (Misc queries) 3 September 12th 06 12:07 PM
Macro, Copy Selected Cells Down a Column DB33 Excel Discussion (Misc queries) 9 February 15th 06 09:29 PM
Copy Selected cells down a row with macro DB33 Excel Discussion (Misc queries) 1 February 15th 06 05:33 PM
Macro to delete data in 'green' cells only Steve Excel Worksheet Functions 7 March 19th 05 01:40 PM


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

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"