Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 62
Default selecting a range according to the longest column

Say, I have data in A1-A3, B1-B7, C1-C5. How do I programmatically
select A1-C7 with one command?

"range([A1],C[1].end(xldown)).select" doesn't do it.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default selecting a range according to the longest column

depends on what you know about your data

Range("A1").CurrentRegion.Resize(,3).Select

if there are no completely blank rows before you get to the bottom.

Dim maxrow as long, i as long, rw as Long
maxrow = 0
for i = 1 to 3
rw = cells(rows.count,i).End(xlup).Row
if rw maxrow then maxrow = rw
Next i
Range("A1").Resize(rw,3).Select


Many might suggest

ActiveSheet.UsedRange.Select

That will often work, but there is no guarantee.


This is pretty resiliant:

Sub GetRealLastCell()
Dim RealLastRow As Long
Dim RealLastColumn As Long
On Error Resume Next
RealLastRow = _
Range("A:C").Find("*", [A1], , , xlByRows, xlPrevious).Row
RealLastColumn = _
Range("A:C").Find("*", [A1], , , xlByColumns, xlPrevious).Column
Range("A1",Cells(RealLastRow, RealLastColumn)).Select
End Sub


--
Regards,
Tom Ogilvy


"John Smith" wrote in message
...
Say, I have data in A1-A3, B1-B7, C1-C5. How do I programmatically
select A1-C7 with one command?

"range([A1],C[1].end(xldown)).select" doesn't do it.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 947
Default selecting a range according to the longest column

If there is no surrounding data, then one of a few ways...

[A1].CurrentRegion.Select

HTH
Dana DeLouis


John Smith wrote:
Say, I have data in A1-A3, B1-B7, C1-C5. How do I programmatically
select A1-C7 with one command?

"range([A1],C[1].end(xldown)).select" doesn't do it.

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
Cell/column auto adjusts width to longest text string redsanders Excel Discussion (Misc queries) 4 July 17th 07 11:02 PM
return cell address of longest text string in a range Dave F[_2_] Excel Discussion (Misc queries) 2 July 12th 07 03:41 PM
Selecting Column Range Desert Piranha[_14_] Excel Programming 2 December 10th 05 09:38 PM
Longest string in a column Jeff Kantner Excel Worksheet Functions 6 December 1st 05 05:56 AM
Selecting a range using a column number reference PCLIVE Excel Programming 7 October 14th 05 04:59 PM


All times are GMT +1. The time now is 01:51 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"