+ Reply to Thread
Results 1 to 7 of 7

Correct syntax to add a workbook name that is stored in a variable into a formula

  1. #1
    Forum Contributor
    Join Date
    08-16-2010
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    132

    Correct syntax to add a workbook name that is stored in a variable into a formula

    Hello.

    I have the following code, which executes just fine:

    Please Login or Register  to view this content.
    The problem is that I need to run this again in a different column, and the data is held in another sheet that I have given the variable StepTwo to.

    I'm not sure of the syntax to do this. Basically - this is what I need the code to do:

    Please Login or Register  to view this content.
    Understandably this is totally incorrect, but it's the best I can do to explain what I'm actually trying to do....

    The two parts of SUMIF are both held in a workbook that I've given the variable "StepTwo" to.
    Both sets of data are also held on Sheet(1) of that workbook.

    Help?

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Correct syntax to add a workbook name that is stored in a variable into a formula

    Try something like this (not tested).

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Forum Contributor
    Join Date
    08-16-2010
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    132

    Re: Correct syntax to add a workbook name that is stored in a variable into a formula

    Thanks so much. Is there a website that shows how to correctly do the syntax for this? I've posted about 3 or 4 times for different scenarios involving using variable names in formulas. e.g. - where to add the single quotes ( ' ) and the brackets ( [ ] )

  4. #4
    Forum Contributor
    Join Date
    08-16-2010
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    132

    Re: Correct syntax to add a workbook name that is stored in a variable into a formula

    I just realized this is a SUMIF, so I need 3 variables, not just 2. I've tried adding it in, but I'm getting another syntax error.

    Please Login or Register  to view this content.
    This should read:
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.

    I did something wrong though, and I'm getting an Application-defined or object-defined error....

  5. #5
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Correct syntax to add a workbook name that is stored in a variable into a formula

    I'm not sure what the result is supposed to be, but I suspect something like this is what you want:
    Please Login or Register  to view this content.
    Remember what the dormouse said
    Feed your head

  6. #6
    Forum Contributor
    Join Date
    08-16-2010
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    132

    Re: Correct syntax to add a workbook name that is stored in a variable into a formula

    I was working directly off of what Alphafrog gave me. His formula worked perfectly - the syntax, that is. I just needed to add an additional line in the middle, and I am not getting the syntax correct. (As =SUMIF has 3 properties, not just 2)

  7. #7
    Forum Contributor
    Join Date
    08-16-2010
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    132

    Re: Correct syntax to add a workbook name that is stored in a variable into a formula

    Okay! i got this to work by removing some of the crazy references I had in there. The variable I had listed as "StepTwo" will always be the same, thus, I can just use the Range() command, like so:

    Please Login or Register  to view this content.
    My question now - to finalize this.....

    This reports a bunch of =SUMIFs back to me, which is awesome, but I'd like for it ONLY to show a value if that value is NOT zero.

    Right now, I'm using this:

    Please Login or Register  to view this content.
    But it's 5000 lines, and it takes about 3 minutes to run, which is bad.

    Is there a way I can do something I can do up front in the original formula for this? If not, I guess I could sort least to greatest, auto filter, select cells 2 to lastrow, then delete... that would be quicker than my for statement.

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

    Re: Correct syntax to add a workbook name that is stored in a variable into a formula

    You might want to look at the External argument of the Address property wnich includes the sheet name in the result.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

+ 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. [SOLVED] Correct syntax for formula for data in different columns
    By sam503 in forum Excel General
    Replies: 3
    Last Post: 02-21-2014, 03:21 PM
  2. Correct syntax for using variable in range selection
    By coasterman in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-16-2012, 11:52 AM
  3. correct syntax for if formula
    By tryer in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-16-2011, 11:29 AM
  4. Replies: 2
    Last Post: 05-11-2010, 11:58 PM
  5. Correct VBA syntax for cell function formula
    By mikeburg in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-15-2005, 01:05 AM

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