+ Reply to Thread
Results 1 to 3 of 3

Using variables in VBA SUM

  1. #1
    Registered User
    Join Date
    02-18-2020
    Location
    London
    MS-Off Ver
    2010
    Posts
    75

    Using variables in VBA SUM

    Hello

    I'm a newbie so please excuse this simple problem.

    I'd like to save two cell addresses into variables and then use them in a VBA SUM command, but the following does not work, perhaps you could explain where I'm going wrong...


    Sub Test()

    Dim StartValue As String
    Dim EndValue As String

    StartValue = ActiveCell.Address
    Selection.Offset(2, 0).Select
    EndValue = ActiveCell.Address

    Range("P4") = Application.WorksheetFunction.Sum(Range(StartValue:EndValue))

    End Sub

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,422

    Re: Using variables in VBA SUM

    You WILL get asked to add Code Tags to comply with forum rules. Best do that sooner rather than later.

    This works:

    Please Login or Register  to view this content.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,422

    Re: Using variables in VBA SUM

    Note: 12 months and 36 posts is NOT a newbie. Best read the forum rules.

+ 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] [Windows Environment Variables] Change user variables using VBA
    By alexgoaga in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-29-2018, 09:06 PM
  2. Storing variables as string or as variables in array performance
    By jakopak in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-20-2017, 08:35 AM
  3. [SOLVED] finding an output from 5 variables in an array using exterior input user variables
    By Allsort in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-09-2013, 11:16 AM
  4. PLEASE HELP!!!Variables, Variable everyone loves variables!
    By THEEXCELGEEK in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-28-2013, 02:20 PM
  5. Replies: 3
    Last Post: 09-11-2012, 02:03 AM
  6. macro that finds variables in one column and enters values if variables found
    By xln00b in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-07-2010, 08:22 AM
  7. Unzip Code - Works without Variables, Breaks with Variables...
    By AdamParker in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-06-2009, 02:35 PM

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