+ Reply to Thread
Results 1 to 5 of 5

Using a variable in a Formula: Quotes don't work

  1. #1
    Registered User
    Join Date
    05-26-2013
    Location
    India
    MS-Off Ver
    Office 2010, 2019
    Posts
    79

    Using a variable in a Formula: Quotes don't work

    I have a dynamic range that I want to sum. I'm using lastRow to find the last row of data. The problem is that once I wrap the formula in quotes VBA does not recognize lastrow as a variable. I've tried all sorts of quote combinations - double quotes, triple quotes, apostrophes, etc. None seem to work. The code below does not work.

    Please Login or Register  to view this content.
    It returns =SUM("A2:A" & lastrow) in cell G3.

    Any help would be greatly appreciated.

  2. #2
    Valued Forum Contributor quekbc's Avatar
    Join Date
    01-18-2010
    Location
    Sydney, Australia
    MS-Off Ver
    2010, 2013, 2016
    Posts
    1,149

    Re: Using a variable in a Formula: Quotes don't work

    You're missing the ampersand and quotation marks for the closing parenthesis and another one quotation mark just after A""

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    05-26-2013
    Location
    India
    MS-Off Ver
    Office 2010, 2019
    Posts
    79

    Re: Using a variable in a Formula: Quotes don't work

    Thank you. I added these; lastRow is now recognized (it changes to an uppercase 'R' as in the Dim), but I'm still getting a runtime error 1004 on that line. Could it have something to do with the version of Excel that I'm using right now (Excel 2007)? Is there a way around this?

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

    Re: Using a variable in a Formula: Quotes don't work

    You don't want quotes in the formula (you wouldn't use them in a cell), and you should use a Long, not Integer, for row variables:
    Please Login or Register  to view this content.
    Remember what the dormouse said
    Feed your head

  5. #5
    Registered User
    Join Date
    05-26-2013
    Location
    India
    MS-Off Ver
    Office 2010, 2019
    Posts
    79

    Re: Using a variable in a Formula: Quotes don't work

    Thank you. That works. And thank you for the advice about using Long.

+ 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. Excel query problems with VBA/ADO to iSeries... date formatting, pass variable w/ quotes
    By anthallen_dps in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-04-2013, 05:08 PM
  2. Unable to get range variable to work in Vlookup formula
    By ZmeY in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-04-2012, 11:28 PM
  3. Remove text between quotes, variable length and number of quotes
    By JP Romano in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-14-2011, 10:40 AM
  4. Adding quotes around a variable url?
    By Zarkov in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-20-2010, 04:20 PM
  5. Wrap variable in quotes?
    By Rick_Stanich in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-14-2009, 01:34 PM
  6. Formula with Variable without quotes
    By greatvvhite in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-04-2009, 05:28 PM
  7. Setting a cell's value as a formula containing quotes or double quotes using vba
    By Metshrine in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-09-2006, 04:10 AM
  8. Replies: 6
    Last Post: 07-11-2006, 02:10 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