Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Cell/column auto adjusts width to longest text string | Excel Discussion (Misc queries) | |||
return cell address of longest text string in a range | Excel Discussion (Misc queries) | |||
Selecting Column Range | Excel Programming | |||
Longest string in a column | Excel Worksheet Functions | |||
Selecting a range using a column number reference | Excel Programming |