+ Reply to Thread
Results 1 to 5 of 5

How do I define a range of cells without using the "Range" property

  1. #1
    Registered User
    Join Date
    07-29-2013
    Location
    California, United States
    MS-Off Ver
    Excel 2010
    Posts
    49

    How do I define a range of cells without using the "Range" property

    I need to sort an entire worksheet going from Columns A to J, and from Rows 2 to n. "n" is a variable that represents a number that will change from time to time.

    For now, let's just say that n=10. But it can be anything like 12, 14, 20, 100, etc. It will change every time.

    I can't just use Range("A2:J10"), because it will not always be J10. It might be J12, J14, J20, J100, etc. I can't use Range("A2:Jn").Sort, because it doesn't recognize "n" as a number there. There is no such thing as Range.(Cells(2,1):Cells(10,n)).Sort

    What else can I use besides the Range property to select an entire range of cells?

    Range("A2:J_").Sort Key1:=Columns("A")

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: How do I define a range of cells without using the "Range" property

    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    07-29-2013
    Location
    California, United States
    MS-Off Ver
    Excel 2010
    Posts
    49

    Re: How do I define a range of cells without using the "Range" property

    Thanks. I actually found out that Range(Cells(2,1),Cells(10,n)).Sort also works. But now I'm having trouble sorting because of something else. The text I have to sort in ascending order are similar to the following:

    01A010
    02A012
    01A015
    01A004

    I didn't format them as "text," but maybe excel does so automatically.

    It should be sorted such that the order is

    01A004
    01A010
    01A015
    02A012

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: How do I define a range of cells without using the "Range" property

    Sorts fine for me exactly as copied from your post. Make sure you don't have any spurious spaces or other characters.
    Last edited by shg; 08-19-2013 at 06:55 PM.

  5. #5
    Registered User
    Join Date
    07-29-2013
    Location
    California, United States
    MS-Off Ver
    Excel 2010
    Posts
    49

    Re: How do I define a range of cells without using the "Range" property

    Thanks shg. I just switched the columns and rows :P.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Error: "Unable to get the interior property of the range class."
    By wunderfisch in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-18-2013, 03:18 PM
  2. Writing a formula in a macro. How do I define the range as "start to end?"
    By ChrisF79 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-06-2013, 02:58 PM
  3. Run-time error 1004; "Unable to set the Hidden property of the Range Class"
    By danimal_time in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-22-2012, 01:06 PM
  4. "Unable to set FormulaArry property of the range class" - Error
    By drgogo in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-17-2010, 02:19 PM
  5. "Unable to set the Hidden property of the Range class" when unhiding cells
    By Kaigi in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-30-2009, 03:33 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1