Results 1 to 4 of 4

Thread: Excel: set a range by its name [SELF-RESOLVED]

  1. #1

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Excel: set a range by its name [SELF-RESOLVED]

    I have this VBA code in a Excel spreadsheet:
    VB Code:
    1. Dim vTarget As range
    2. Private Sub Workbook_Open()
    3.     Set vTarget = Range("Sheet1!$B$3")
    4. End Sub
    Now, cell $B$3 has been assigned the name "Volume". I want to set the vTarget variable using the name "Volume" rather than the cell address. I've tried different syntax but always get some kind of error.
    Last edited by krtxmrtz; Jul 3rd, 2006 at 06:50 AM.
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  2. #2

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Excel: set a range by its name

    VB Code:
    1. Dim vTarget As range
    2. Private Sub Workbook_Open()
    3.     Set vTarget = Range(ThisWorkbook.Names("Volume"))
    4. End Sub
    It wasn't that difficult after all.
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  3. #3
    Frenzied Member zaza's Avatar
    Join Date
    Apr 2001
    Location
    Borneo Rainforest Habits: Scratching
    Posts
    1,486

    Re: Excel: set a range by its name [SELF-RESOLVED]

    VB Code:
    1. Private Sub Workbook_Open()
    2.     Dim vTarget As range
    3.     Set vTarget = Range("Volume")
    4. End Sub


    That will also work.


    zaza
    I use VB 6, VB.Net 2003 and Office 2010



    Code:
    Excel Graphing | Excel Timer | Excel Tips and Tricks | Add controls in Office | Data tables in Excel | Gaussian random number distribution (VB6/VBA,VB.Net) | Coordinates, Vectors and 3D volumes

  4. #4

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Excel: set a range by its name [SELF-RESOLVED]

    Quote Originally Posted by zaza
    VB Code:
    1. Private Sub Workbook_Open()
    2.     Dim vTarget As range
    3.     Set vTarget = Range("Volume")
    4. End Sub


    That will also work.


    zaza
    Right, thanks for pointing out.
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

Posting Permissions

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



Click Here to Expand Forum to Full Width