+ Reply to Thread
Results 1 to 3 of 3

SUM when using a looping macro of variable length

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    06-18-2015
    Location
    Milton Keynes
    MS-Off Ver
    2016
    Posts
    101

    SUM when using a looping macro of variable length

    Hi guys,
    I'm making a spreadsheet to record call stats in a call center.

    The call center has fluctuating employee levels due to the norm (Promotion, employees leaving etc.)

    I've therefore made a looping Macro to fill out the call stats where the user enters the number of employees they are filling the report out for.
    This number is "x" and is the basis of the looping macro (For I is 1 to X...)

    However, i need to do some sums on a column of data of indeterminate length.

    I have come up with

    ActiveCell.FormulaR1C1 = "=SUM(R[-X]C:R[-1]C)"
    The second digit will always be -1 as this is going to the bottom of the list. However, is there a way to get excel to take the first value as -x?

    I've always used R1C1 format as this tends to be the format that my Excel automatically registers when I record some of the more mundane parts of the macro.

    If it wasn't then it would be easy, as this value would always be 4 (A4,B4....)

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

    Re: SUM when using a looping macro of variable length

    Not quite sure I follow what you want. As syntax examples, these are all valid.

    ActiveCell.FormulaR1C1 = "=SUM(R[-" & X & "]C:R[-1]C)"

    ActiveCell.FormulaR1C1 = "=SUM(R4C:R[-1]C)"

    ActiveCell.Formula = "=SUM(A4:A" & i & ")"
    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
    06-18-2015
    Location
    Milton Keynes
    MS-Off Ver
    2016
    Posts
    101

    Re: SUM when using a looping macro of variable length

    Thanks Alpha,
    I was missing " & X & "

+ 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. Replies: 5
    Last Post: 06-18-2015, 09:10 AM
  2. Looping through a variable with macro and autofilter
    By CLoos in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-20-2013, 06:06 PM
  3. Replies: 3
    Last Post: 11-21-2012, 03:28 PM
  4. [SOLVED] Macro to Sum several data sets(variable length) in the same column
    By mahtabshaikh in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-25-2012, 08:34 AM
  5. Replies: 6
    Last Post: 04-14-2012, 04:07 AM
  6. Copy variable length column to clipboard within a macro
    By DanBlum in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-21-2009, 09:15 AM
  7. Replies: 1
    Last Post: 06-01-2005, 11: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