ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Defining a range (https://www.excelbanter.com/excel-programming/436266-defining-range.html)

brichard429

Defining a range
 
I want to sort a table that grows with additional data. The top left value
never changes and is Range("B6") but the bottom right cell will change as the
table grows. How do I go about defining the range?
--
Bernie

JBeaucaire[_131_]

Defining a range
 
Something like:
========
Dim RNG as Range
Set RNG = Range("B6", Range("B6").SpecialCells(xlCellTypeLastCell))

RNG.Sort Key1:=Range("B6"), Order1:=xlDescending
=======

Does that help you get started?
--
"Actually, I *am* a rocket scientist." -- JB
(www.MadRocketScientist.com)

Your feedback is appreciated, click YES if this post helped you.


"brichard429" wrote:

I want to sort a table that grows with additional data. The top left value
never changes and is Range("B6") but the bottom right cell will change as the
table grows. How do I go about defining the range?
--
Bernie


OssieMac

Defining a range
 
Hi Bernie,

Note that a space and underscore at the end of a line is a line break in an
otherwise single line of code.

Dim rngMyRange As Range

'Edit "Sheet1" to your sheet name
With Sheets("Sheet1")

'Edit "E" to your last column of range
Set rngMyRange = .Range(.Cells(6, "B"), _
.Cells(.Rows.Count, "E").End(xlUp))

End With
--
Regards,

OssieMac


"brichard429" wrote:

I want to sort a table that grows with additional data. The top left value
never changes and is Range("B6") but the bottom right cell will change as the
table grows. How do I go about defining the range?
--
Bernie


brichard429

Defining a range
 
Thank you both for your feedback. After working with your suggestions I came
up with this solution
Range(Range("B6"), Range("B6").End(xlDown).End(xlToRight)).Select
--
Bernie


"brichard429" wrote:

I want to sort a table that grows with additional data. The top left value
never changes and is Range("B6") but the bottom right cell will change as the
table grows. How do I go about defining the range?
--
Bernie


brichard429

Defining a range
 
Thank you both for your suggestions, I used them to come up with this:
Range(Range("B6"), Range("B6").End(xlDown).End(xlToRight)).Select
which work for me.
--
Bernie


"brichard429" wrote:

I want to sort a table that grows with additional data. The top left value
never changes and is Range("B6") but the bottom right cell will change as the
table grows. How do I go about defining the range?
--
Bernie



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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com