+ Reply to Thread
Results 1 to 3 of 3

Wanting to send a formula to a Cell using VBA and a variable sheet name defined with code.

  1. #1
    Registered User
    Join Date
    05-24-2013
    Location
    Las Vegas
    MS-Off Ver
    Excel 2007
    Posts
    26

    Wanting to send a formula to a Cell using VBA and a variable sheet name defined with code.

    Hello All,

    Well, It's been a long time but using books, Google, Forum searches and a lot of trial / error, I think I'm on my way to figuring this Excel and VBA out. The more I can see it coming together and working, the more motivating it is. Last night I came across an issue that I cannot seem to find the solution to, and I know it's in the syntax of the code. I am trying to use VBA to send a formula to a Cell using a variable sheetname defined as a string. My workbook has several sheets, each representing different years. So, If "X" didn't happen this year, then return the value from last year. The formula is a Lookup statement inside an If statement returning the corresponding date.

    The formula in the Cell Looks like:

    =IF(D11=0,'2012 Attnd'!E11,LOOKUP(2,1/($AJ11:$OJ11="X"),$AJ$5:$OJ$5))

    Recording this as a macro gives me the following VBA code:

    Please Login or Register  to view this content.
    My goal is to replace '2012 Attnd'! with the variable LastYearSheet as defined in my VBA code. The variable is set as a string and holds the correct value. I am just struggling with the number of quote marks, apostrophe marks and maybe an ampersand or two.

    Once again, I thank you all for your time and assistance. I look forward to continuing my VBA education as the more I get into it the more motivating it becomes.

    Scott
    Last edited by sdavison; 07-12-2013 at 04:50 PM.

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

    Re: Wanting to send a formula to a Cell using VBA and a variable sheet name defined with c

    Scott

    This should do it.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    05-24-2013
    Location
    Las Vegas
    MS-Off Ver
    Excel 2007
    Posts
    26

    Re: Wanting to send a formula to a Cell using VBA and a variable sheet name defined with c

    Norie,

    Thank you for your quick reply. Yes, that is exactly what I was trying to accomplish most of last night. I just had the syntax wrong. But now that I see how it pieces together, I can utilize it for other formulas. It's forum members like you for whom I am most thankful. Because you are willing to take the time and effort to assist us beginners by giving us a push in the right direction, we are able to further our understanding of how this language works.

    Thank you again,

    Scott

+ 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