Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 57
Default selecting an area with VBA

<a
href="http://msdn.microsoft.com/newsgroups/default.aspx?query=gerstman&dg=microsoft.public.ex cel.programming&cat=en-us-msdn-officedev-excel&lang=en&cr=US&pt=f3f7ac8a-4ea0-4c36-bed9-8feae6d75298&catlist=B7714BAA-0D60-40B0-A226-8B9CF33299A5%2C774F24A2-F71F-425F-AC2B-DC48AB0DA5C9&dglist=&ptlist=&exp=&sloc=en-us"Earlier</a I asked about defining a range for non-contiguous data.

The answer involved going to the bottom of the page and then using xlUp to
hit the last row of data. Like this:

Set poc_range = ActiveSheet.Range("b2", Cells(Rows.Count, 2).End(xlUp))

Now what I'd like to do is something similar. I'd like to be able to get a
range that covers <strongboth</strong the rows and columns and then select
it. Is that possible, or can I only specify one direction at a time?

David
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,311
Default selecting an area with VBA

Maybe something like this.

Set poc_range = ActiveSheet.Range("b2", ActiveCell.SpecialCells(xlLastCell))

Regards,
Paul

"David Gerstman" wrote in message
...
<a
href="http://msdn.microsoft.com/newsgroups/default.aspx?query=gerstman&dg=microsoft.public.ex cel.programming&cat=en-us-msdn-officedev-excel&lang=en&cr=US&pt=f3f7ac8a-4ea0-4c36-bed9-8feae6d75298&catlist=B7714BAA-0D60-40B0-A226-8B9CF33299A5%2C774F24A2-F71F-425F-AC2B-DC48AB0DA5C9&dglist=&ptlist=&exp=&sloc=en-us"Earlier</a
I asked about defining a range for non-contiguous data.

The answer involved going to the bottom of the page and then using xlUp to
hit the last row of data. Like this:

Set poc_range = ActiveSheet.Range("b2", Cells(Rows.Count, 2).End(xlUp))

Now what I'd like to do is something similar. I'd like to be able to get a
range that covers <strongboth</strong the rows and columns and then
select
it. Is that possible, or can I only specify one direction at a time?

David



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default selecting an area with VBA

Sub LastCell()
Dim poc_range As Range

Set poc_range = ActiveSheet.Range("B2").Resize(LastRow - 1, LastCol - 1)

poc_range.Select
End Sub


'-----------------------------------------------------------------
Function LastRow() As Long
'-----------------------------------------------------------------
LastRow = Cells.Find(What:="*", _
After:=Range("A1"), _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
End Function

'-----------------------------------------------------------------
Function LastCol() As Long
'-----------------------------------------------------------------
LastCol = Cells.Find(What:="*", _
After:=Range("A1"), _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious).Column
End Function





--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"David Gerstman" wrote in message
...
<a

href="http://msdn.microsoft.com/newsgroups/default.aspx?query=gerstman&dg=mi
crosoft.public.excel.programming&cat=en-us-msdn-officedev-excel&lang=en&cr=U
S&pt=f3f7ac8a-4ea0-4c36-bed9-8feae6d75298&catlist=B7714BAA-0D60-40B0-A226-8B
9CF33299A5%2C774F24A2-F71F-425F-AC2B-DC48AB0DA5C9&dglist=&ptlist=&exp=&sloc=
en-us"Earlier</a I asked about defining a range for non-contiguous data.

The answer involved going to the bottom of the page and then using xlUp to
hit the last row of data. Like this:

Set poc_range = ActiveSheet.Range("b2", Cells(Rows.Count, 2).End(xlUp))

Now what I'd like to do is something similar. I'd like to be able to get a
range that covers <strongboth</strong the rows and columns and then

select
it. Is that possible, or can I only specify one direction at a time?

David



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
selecting text area dave7 Excel Worksheet Functions 1 January 24th 07 04:22 PM
Mouse not selecting area correctly DLana Raven Excel Worksheet Functions 1 August 30th 06 06:11 PM
Method of selecting an area with a macro WildGlio Excel Worksheet Functions 1 March 25th 05 06:55 PM
selecting used area JulieD Excel Programming 1 July 5th 04 11:53 AM


All times are GMT +1. The time now is 03:43 AM.

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

About Us

"It's about Microsoft Excel"