+ Reply to Thread
Results 1 to 3 of 3

AutoSum macros

  1. #1
    Registered User
    Join Date
    06-13-2006
    Posts
    46

    AutoSum macros

    With alot of reading, I have been able to piece together some code to auto sum a variable length column. My column data is coming from a filtered column on a separate worksheet. My problem is, the code stops when the filtered column from the other sheet has no data present. (Data is filtered off of date entries and sometimes there is no data for a specific date). How do I stop the code if there is no data to sum? Here is the macro:

    Sub totalcolumn()
    'To position the cursor in the "AutoSum" cell
    Range("Q2").End(xlDown).Offset(1, 0).Select
    'Determine the Row numbers
    vRowTop = 2
    vRowBottom = ActiveCell.Offset(-1, 0).Row
    'Compute the R[ ] variable
    vDiff = vRowBottom - vRowTop + 1
    'Enter the formulas
    Selection.FormulaR1C1 = "=SUM(R[" & -vDiff & "]C:R[-1]C)"
    'Move the cursor one cell to the right
    Selection.Offset(0, 1).Select
    'To enter the =Sum formula in the second column of data
    Selection.FormulaR1C1 = "=SUM(R[" & -vDiff & "]C:R[-1]C)"
    Columns("Q:R").Select


    End Sub

  2. #2
    Bob Phillips
    Guest

    Re: AutoSum macros

    Sub totalcolumn()
    'To position the cursor in the "AutoSum" cell
    Range("Q2").End(xlDown).Offset(1, 0).Select
    'Determine the Row numbers
    vRowTop = 2
    vRowBottom = ActiveCell.Row - 1
    If vRowBottom = Rows.Count And Range("Q2").Value = "" Then
    'do nothing
    Else
    'Compute the R[ ] variable
    vDiff = vRowBottom - vRowTop + 1
    'Enter the formulas
    Selection.FormulaR1C1 = "=SUM(R[" & -vDiff & "]C:R[-1]C)"
    'Move the cursor one cell to the right
    'To enter the =Sum formula in the second column of data
    Selection.Offset(0, 1).FormulaR1C1 = "=SUM(R[" & -vDiff &
    "]C:R[-1]C)"
    Columns("Q:R").Select
    End If
    End Sub



    --
    HTH

    Bob Phillips

    (replace somewhere in email address with gmail if mailing direct)

    "Lvenom" <[email protected]> wrote in
    message news:[email protected]...
    >
    > With alot of reading, I have been able to piece together some code to
    > auto sum a variable length column. My column data is coming from a
    > filtered column on a separate worksheet. My problem is, the code stops
    > when the filtered column from the other sheet has no data present.
    > (Data is filtered off of date entries and sometimes there is no data
    > for a specific date). How do I stop the code if there is no data to
    > sum? Here is the macro:
    >
    > Sub totalcolumn()
    > 'To position the cursor in the "AutoSum" cell
    > Range("Q2").End(xlDown).Offset(1, 0).Select
    > 'Determine the Row numbers
    > vRowTop = 2
    > vRowBottom = ActiveCell.Offset(-1, 0).Row
    > 'Compute the R[ ] variable
    > vDiff = vRowBottom - vRowTop + 1
    > 'Enter the formulas
    > Selection.FormulaR1C1 = "=SUM(R[" & -vDiff & "]C:R[-1]C)"
    > 'Move the cursor one cell to the right
    > Selection.Offset(0, 1).Select
    > 'To enter the =Sum formula in the second column of data
    > Selection.FormulaR1C1 = "=SUM(R[" & -vDiff & "]C:R[-1]C)"
    > Columns("Q:R").Select
    >
    >
    > End Sub
    >
    >
    > --
    > Lvenom
    > ------------------------------------------------------------------------
    > Lvenom's Profile:

    http://www.excelforum.com/member.php...o&userid=35358
    > View this thread: http://www.excelforum.com/showthread...hreadid=551298
    >




  3. #3
    Registered User
    Join Date
    06-13-2006
    Posts
    46

    Autosum macro

    Thank you for the response.
    After a little playing around ( and learning the concept behind If, Then, Else and End If), I was able to make this work just fine. Again thank you for the help, people such as yourself provide a great support and learning service for others that are less proficient (such as myself).

+ 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