+ Reply to Thread
Results 1 to 6 of 6

set a variable equal to a value in a named cell

  1. #1
    Registered User
    Join Date
    12-22-2003
    Location
    Texas
    Posts
    90

    set a variable equal to a value in a named cell

    I named a cell in a worksheet using the Inset->name->define tool. I can always back track to it using the drop-down arrow in the upper left hand of the worksheet and I know the code in VBA to activate that cell as well.

    Application.Goto Reference:="namedcell001"

    My question is - how do I set a variable = to the value in that named cell without activating that cell?

    similar to var1 = Sheets("Model").Range("R12")

    it would read something like this:
    var1 = namedcell001

    but the above (and several variations of it) does not work.
    Barrfly

  2. #2
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: set a variable equal to a value in a named cell

    Please Login or Register  to view this content.
    Note that the sheet name is not needed
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  3. #3
    Registered User
    Join Date
    12-22-2003
    Location
    Texas
    Posts
    90

    Re: set a variable equal to a value in a named cell

    perfect. simple solution yet elusive (for me today at least). Thanks for the quick response.

  4. #4
    Forum Contributor
    Join Date
    11-10-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    549

    Re: set a variable equal to a value in a named cell

    Hi

    I think I'm trying to do the same thing as the post originator but when I follow the instructions I still can't get it to work. Note I am a beginner with Visual Basic.

    I have a named cell called "this" with the following value "AS41005.2". These are in a worksheet called "Sections".

    I want to press a button which then looks up the value "AS41005.2" in another worksheet called "Calculation" and then lands on it - just like the FIND function in excel.

    I have no problem with installing and using the button, but can't get the programing to work out. A lot of the time on the forums I can't understand if the codes are in full or in snippets.

    My full code (which isn't working) is:

    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Sub Macro1()

    Dim x As Variant
    x = Range("this").Value
    Sheets("Calculation").Select
    Application.Goto Reference:=x

    End Sub
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    Any help will be appreciated.

  5. #5
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: set a variable equal to a value in a named cell

    Excel_&_Help, Welcome to the Board, however, please note

    Your post does not comply with Rule 2 of our Forum RULES. Don't post a question in the thread of another member -- start your own thread. If you feel it's particularly relevant, provide a link to the other thread.


    Further, please also ensure you encase your VBA in CODE tags per forum requirements.

  6. #6
    Forum Contributor
    Join Date
    11-10-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    549

    Re: set a variable equal to a value in a named cell

    Apologies as I haven't done much of this before. I submitted a new post

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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