PC Review


Reply
Thread Tools Rate Thread

AutoSum macros

 
 
Lvenom
Guest
Posts: n/a
 
      13th Jun 2006

With alot of reading, I have been able to piece together some code t
auto sum a variable length column. My column data is coming from
filtered column on a separate worksheet. My problem is, the code stop
when the filtered column from the other sheet has no data present
(Data is filtered off of date entries and sometimes there is no dat
for a specific date). How do I stop the code if there is no data t
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 Su

--
Lveno
-----------------------------------------------------------------------
Lvenom's Profile: http://www.excelforum.com/member.php...fo&userid=3535
View this thread: http://www.excelforum.com/showthread.php?threadid=55129

 
Reply With Quote
 
 
 
 
Bob Phillips
Guest
Posts: n/a
 
      13th Jun 2006
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" <(E-Mail Removed)> wrote in
message news:(E-Mail Removed)...
>
> 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
>



 
Reply With Quote
 
Lvenom
Guest
Posts: n/a
 
      15th Jun 2006

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. Agai
thank you for the help, people such as yourself provide a great suppor
and learning service for others that are less proficient (such a
myself)

--
Lveno
-----------------------------------------------------------------------
Lvenom's Profile: http://www.excelforum.com/member.php...fo&userid=3535
View this thread: http://www.excelforum.com/showthread.php?threadid=55129

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How 2 sort an autosum total list after adding items 2 autosum item akm Microsoft Excel Misc 0 30th May 2010 11:44 PM
Autosum Max Microsoft Excel Programming 3 10th Aug 2009 12:04 PM
autosum capital me Microsoft Excel Misc 3 5th Apr 2009 05:28 AM
autosum with Macros chris Microsoft Excel Misc 1 28th Aug 2003 02:58 AM
No Autosum??? rd Microsoft Access 0 25th Jul 2003 08:55 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:55 PM.