+ Reply to Thread
Results 1 to 5 of 5

Dynamic Cell Reference in VBA Formula

Hybrid View

  1. #1
    Registered User
    Join Date
    08-26-2009
    Location
    Lima, Peru
    MS-Off Ver
    Excel 2007
    Posts
    37

    Question Dynamic Cell Reference in VBA Formula

    Hi,

    Background Information:
    I am creating a DASHBOARD sheet to be at the beginning of my workbook with multiple sheets.

    In DASHBOARD I have created a chart that contains client analysis formulas that reference to the appropriate client sheet name in the same workbook by reference to Cell C8. To do this, in each statistics formula I have used the Indirect reference: =INDIRECT("'" & C8 &"'!G3")

    My next step is to make a dynamic button that also uses Cell C8 as the sheet name to jump to. AKA: I want the "Go" button to jump the user exactly to the client sheet which is named in cell C8.

    I have used this simple VBA to use a button to jump to a sheet name:
    Private Sub Client_Click()
    
    Sheets("Client-Template").Select
    
    End Sub
    I need help to make the sheet reference dynamically linked to the contents of Cell C8 which will have the exact worksheet name of any of the clients:
    The following is my failed attempt to create a dynamic variable that depended on Cell C8:
    Private Sub Client_Click()
    Client as String
    
    Client = Range(C8)
    Sheets("Client").Select
    
    End Sub
    Thank you for any and all of your help!
    Last edited by Leith Ross; 08-26-2009 at 11:57 AM. Reason: Added Code Tags

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Dynamic Cell Reference in VBA Formula

    Hello mworonuk,

    Please use code tags to wrap your code. It makes it easier to follow and copy.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Dynamic Cell Reference in VBA Formula

    Hello mworonuk,

    You can do this directly without needing to make a string variable.
    Private Sub Client_Click()
    
    Sheets(Range(C8).Text).Select
    
    End Sub

  4. #4
    Registered User
    Join Date
    08-26-2009
    Location
    Lima, Peru
    MS-Off Ver
    Excel 2007
    Posts
    37

    Re: Dynamic Cell Reference in VBA Formula

    Hi Leith,

    Thanks for the help (and the tip on the code tag).

    I have entered this into the VBA which is linked to the Button Object in the Dashboard:

    Private Sub Client_Click()
    
    Sheets(Range(C8).Text).Select
    
    End Sub


    VBA returns this error:

    Run-time error '1004':
    Method 'Range' of object '_Worksheet' failed

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Dynamic Cell Reference in VBA Formula

    Hello mworonuk,

    Sorry about that, the cell address should have quotes around it like this...
    Private Sub Client_Click()
    
    Sheets(Range("C8").Text).Select
    
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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