+ Reply to Thread
Results 1 to 5 of 5

give range a name

  1. #1
    Forum Contributor
    Join Date
    09-09-2014
    Location
    England
    MS-Off Ver
    2013
    Posts
    100

    give range a name

    I am using the below code to select a range, how would I then name this range so that I can refer to it later in my macro?


    [[Sub ReplaceTitleMs()
    Dim rng As Range
    Set rng = Application.InputBox("Select a range", "Obtain Range Object", Type:=8)

    MsgBox "The cells selected were " & rng.Address

    End Sub]]

    Thank you.

    Z

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,406

    Re: give range a name

    You can refer to the selected range using the object variable rng.
    If posting code please use code tags, see here.

  3. #3
    Forum Contributor
    Join Date
    09-09-2014
    Location
    England
    MS-Off Ver
    2013
    Posts
    100

    Re: give range a name

    Thanks Norie, how would I do that? Excuse the daft question.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,406

    Re: give range a name

    Your code sets rng to refer to the range the user selects, so whenever you want to refer to the selected range use rng.

    Just like you've done here to display the address of the selected range.
    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    09-09-2014
    Location
    England
    MS-Off Ver
    2013
    Posts
    100

    Re: give range a name

    Thanks Norie. That makes sense.

+ 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. [SOLVED] VB Code to give 1st and last row # in selected range
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-05-2015, 02:04 PM
  2. [SOLVED] Need Lookup Formula to Give Column Range
    By rylock in forum Excel General
    Replies: 8
    Last Post: 07-26-2014, 06:46 PM
  3. VBA Code to grab data give critiria in textbox and output data range to cell range. Help!?
    By exclusiveicon in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-26-2014, 05:31 PM
  4. Find within a range give different variables
    By jnh0 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-18-2013, 04:20 AM
  5. 2 inputs to give range of returns
    By Sordini in forum Excel General
    Replies: 6
    Last Post: 09-11-2012, 12:21 PM
  6. [SOLVED] Give RELEVANT responses to questions. DO NOT give usless list
    By pmartin in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-06-2006, 02:00 PM
  7. [SOLVED] Is there any way to give an dynamic name for a range?
    By salut in forum Excel General
    Replies: 1
    Last Post: 12-07-2005, 10:10 AM

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