+ Reply to Thread
Results 1 to 7 of 7

Use variable column reference in VBA worksheet function

  1. #1
    Registered User
    Join Date
    06-25-2014
    Location
    Michigan, US
    MS-Off Ver
    2010
    Posts
    8

    Use variable column reference in VBA worksheet function

    I've been stuck on this for a while now, I hope someone can help. I have the following line in VBA which works.




    Please Login or Register  to view this content.
    I need to replace the range $V:$V because different sheets require different columns as a reference. I have a variable that will change depending on the sheet. How can I work it into the formula using the correct syntax?

    Any help is greatly appreciated!

    Thanks!
    Maria

  2. #2
    Valued Forum Contributor
    Join Date
    11-02-2012
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    564

    Re: Use variable column reference in VBA worksheet function

    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 07-11-2014 at 10:53 PM. Reason: Added missing CODE tags. Please read and follow the Forum Rules, link above in the menu bar. Thanks.
    ________________________________________________________
    If your problem is solved, update the thread as SOLVED: Go to the top of the first post-Select Thread Tools-Select Mark thread as Solved OR - Go to the first post - Click edit- Click Advance- Just below the word "Title:" you will see a dropdown with the word No prefix.- Change to Solve- Click Save.

    Show your gratitude to the person who helped you solving your problem by clicking on star button at the bottom of such post.

  3. #3
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Use variable column reference in VBA worksheet function

    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 07-11-2014 at 10:53 PM. Reason: Added missing CODE tags. Please read and follow the Forum Rules, link above in the menu bar. Thanks.
    Hope this helps

    Sometimes its best to start at the beginning and learn VBA & Excel.

    Please dont ask me to do your work for you, I learnt from Reading books, Recording, F1 and Google and like having all of this knowledge in my head for the next time i wish to do it, or wish to tweak it.
    Available for remote consultancy work PM me

  4. #4
    Registered User
    Join Date
    06-25-2014
    Location
    Michigan, US
    MS-Off Ver
    2010
    Posts
    8

    Re: Use variable column reference in VBA worksheet function

    Haripoupuri,


    Thank you, this helps, but how would I do this if my variable is just the column number? Do I have to have it in a different form?

  5. #5
    Registered User
    Join Date
    06-25-2014
    Location
    Michigan, US
    MS-Off Ver
    2010
    Posts
    8

    Re: Use variable column reference in VBA worksheet function

    Nathansav,

    I understand what you did, I guess my question now is the variable is driven by the active sheet so I don't know I would get it to the format you wrote it in.

  6. #6
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Use variable column reference in VBA worksheet function

    Are you not still using ActSheet in my way?

  7. #7
    Valued Forum Contributor
    Join Date
    11-02-2012
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    564

    Re: Use variable column reference in VBA worksheet function

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    06-25-2014
    Location
    Michigan, US
    MS-Off Ver
    2010
    Posts
    8

    Re: Use variable column reference in VBA worksheet function

    Nathansav,

    I tried that but it still doesn't work. My variable is the name of the sheet, which matches the name of the column that needs to be refereneced, how would I write in into the variable like you did MyStr?

+ 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. Use variable column reference in VBA worksheet function
    By MariaM02 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-08-2014, 08:29 AM
  2. OFFSET function - column reference over the edge of the worksheet
    By ronaldev in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-04-2013, 10:09 PM
  3. how do i reference a worksheet variable in a formula?
    By chemeng1T3 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-06-2012, 08:27 AM
  4. Replies: 2
    Last Post: 10-06-2009, 04:32 AM
  5. how to reference a worksheet with a variable vs a name
    By ibbm in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-17-2006, 03:00 PM

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