Select a range of cells and give it a name

  • This is my first post and I'm sorry if this is a silly question. I can only record macros and haven't delved into writing my own code.


    I would like a macro that selects all the cells in a data set and then gives that range a name. I would also like the macro to prompt the user for the name for the range.

  • Re: Select a range of cells and give it a name


    try the below code:


  • Re: Select a range of cells and give it a name


    Here is another option.



    [SIZE=3]The Only Dumb Question Is A Question Not Asked.[/SIZE]

  • Re: Select a range of cells and give it a name


    From what I can see you don't need code to add a name for a this.


    You can use CurrentRegion which in VBA will refer to all the cells within an area that is contains no completely empty columns or rows.


    If you are using Excel 2007 or later then formatting the data as a Table will automatically add a name such as Table1 which can be used in VBA.


    Both these methods have the advantage that they are not fixed, but are dynamic expanding or contracting as data is added or removed.


    Tables have many more advantages

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!