none
Select Range

    Question

  • If I want to create a macro that will sort a table

    but the table size (columns x rows) is always different.

    What would the code look like, so that it always select the particular range with values?

    Because the rest of the columns and rows are empty, but I could have multiple tables on one sheet, so every time

    I run the code it should look for the table and select it.

    Wednesday, August 28, 2013 7:18 PM

Answers

  • You can use the select xldown, xlright, xlup, xlleft functions to do this as well if your data is consistent. 

    Sub selectGroup()
        Range("A1").Select
        Range(Selection, Selection.End(xlToRight)).Select
        Range(Selection, Selection.End(xlDown)).Select
    End Sub
    

    Wednesday, August 28, 2013 8:48 PM

All replies

  • Hi,

    Do you mean a real table? i.e one that has a name something like Table1 or do you just mean a number of rows and columns?

    If it's a real table then you can use

    [Code]

    Range("Table1[#All]").Select

    [/Code]

    or if it's a number of rows and columns and let's say the top left cell is D1 then you could use

    [Code]

    Range("D1").CurrentRegion.Select

    [/Code]

    It is highly unlikely that you need to select anything to carry out a sort


    • Edited by Mike MLH Wednesday, August 28, 2013 8:37 PM
    Wednesday, August 28, 2013 8:36 PM
  • You can use the select xldown, xlright, xlup, xlleft functions to do this as well if your data is consistent. 

    Sub selectGroup()
        Range("A1").Select
        Range(Selection, Selection.End(xlToRight)).Select
        Range(Selection, Selection.End(xlDown)).Select
    End Sub
    

    Wednesday, August 28, 2013 8:48 PM