[SOLVED] VBA to sum rows


"Excel VBA Help"

 


Play Friv Now - Play Friv Games
Go Back   The Code Cage Forums > Microsoft Topics > Microsoft Excel Forum
Our Info Pages:-
The Code Cage - Microsoft Office help

Notices

Microsoft Excel Forum Members Post questions in this forum if they are related to using Microsoft Excel, this includes Worksheet Functions, Excel VBA Programming, Simple Macro Code & Charting, Excel formula etc.

 
 
Thread Tools Rate Thread Display Modes
  #1  
Old 8th December 2013, 23:18
streub's Avatar
streub streub is offline
Frequent User
MS Office Version: Excel 2007
MS Office Skill Level: Can use VBA
 
Join Date: Jan 2013
Location: Manitowoc WI
Age: 63
Posts: 178
Posts Per Day: 0.10
My Top Tip Count: 1
Thanks to others: 83
Thanked 3 Times in 3 Posts
Reputation: 61 (6) streub will become famous soon enough
1 Top Tips
USA
Default VBA to sum rows
     Excel: VBA   


------ Register to get rid of these "In Post" ads! ------

Category: Excel: VBA   

I have a worksheet with 12 rows each representing a month. There are 31 columns representing each day.

The budget data starts in column C and ends at column AG. The sum of each row is to be in column AH.

I have attempted numerous solutions and search the internet but have had no success. To be honest, I do not know where to start.

It has to be in VBA because this function would be part of a sub.

Steve



The Code Cage Advertisment
Advertisement
  #2  
Old 8th December 2013, 23:29
Simon Lloyd's Avatar
Simon Lloyd Simon Lloyd is offline
Administrator
MS Office Version: MS Office 97 - 2013
MS Office Skill Level: Can use most of MS Office
 
Join Date: Aug 2008
Location: Manchester, England
Age: 53
Posts: 11,884
Posts Per Day: 3.51
My Top Tip Count: 11
Thanks to others: 49
Thanked 441 Times in 425 Posts
Reputation: 6660 (194) Simon Lloyd has a reputation beyond reputeSimon Lloyd has a reputation beyond reputeSimon Lloyd has a reputation beyond reputeSimon Lloyd has a reputation beyond reputeSimon Lloyd has a reputation beyond reputeSimon Lloyd has a reputation beyond reputeSimon Lloyd has a reputation beyond reputeSimon Lloyd has a reputation beyond reputeSimon Lloyd has a reputation beyond reputeSimon Lloyd has a reputation beyond reputeSimon Lloyd has a reputation beyond repute
11 Top Tips
Wales
Default Re: VBA to sum rows

------ Register to get rid of these "In Post" ads! ------


When you say "Sum Rows" do you mean sum each row at AH, Sum all the rows from C to AG or Sum all the results in column AH?

Sum function can be used in vba like this
VBA CODE:
Sub Summing() 
    Dim MySum As Long 
    MySum = Application.WorksheetFunction.Sum(Range("A1:F10")) 
    MsgBox MySum 
End Sub 
Naturallif your using Excel 2007> you can use SumIf's...etc but that should give you a start.
__________________
Regards,
Simon Lloyd
Microsoft Office Help

Want to say thanks? then hit this How to say thanks! button in any post you want to thank
If you find one of my posts helpful then hit this one Helpful Answer in the post that helped most!




Last edited by Simon Lloyd; 9th December 2013 at 01:03.


The Following User Says Thank You to Simon Lloyd For This Useful Post:
streub (9th December 2013)
  #3  
Old 9th December 2013, 00:28
streub's Avatar
streub streub is offline
Frequent User
MS Office Version: Excel 2007
MS Office Skill Level: Can use VBA
 
Join Date: Jan 2013
Location: Manitowoc WI
Age: 63
Posts: 178
Posts Per Day: 0.10
My Top Tip Count: 1
Thanks to others: 83
Thanked 3 Times in 3 Posts
Reputation: 61 (6) streub will become famous soon enough
1 Top Tips
USA
Default Re: VBA to sum rows

------ Register to get rid of these "In Post" ads! ------


Simon you are working very late!

Sum each row (12) C to AG with the total in AH. There should be 12 totals, representing each month, starting in AH:2 down to AH:14.



The Code Cage Advertisment
Advertisement
  #4  
Old 9th December 2013, 01:03
Simon Lloyd's Avatar
Simon Lloyd Simon Lloyd is offline
Administrator
MS Office Version: MS Office 97 - 2013
MS Office Skill Level: Can use most of MS Office
 
Join Date: Aug 2008
Location: Manchester, England
Age: 53
Posts: 11,884
Posts Per Day: 3.51
My Top Tip Count: 11
Thanks to others: 49
Thanked 441 Times in 425 Posts
Reputation: 6660 (194) Simon Lloyd has a reputation beyond reputeSimon Lloyd has a reputation beyond reputeSimon Lloyd has a reputation beyond reputeSimon Lloyd has a reputation beyond reputeSimon Lloyd has a reputation beyond reputeSimon Lloyd has a reputation beyond reputeSimon Lloyd has a reputation beyond reputeSimon Lloyd has a reputation beyond reputeSimon Lloyd has a reputation beyond reputeSimon Lloyd has a reputation beyond reputeSimon Lloyd has a reputation beyond repute
11 Top Tips
Wales
Default Re: VBA to sum rows

------ Register to get rid of these "In Post" ads! ------


I'm working nights (12 hours!!)
This will sum each row 1 to 12 and put the static result in AH (assuming you're starting at row 2)
VBA CODE:
Sub Summing() 
    Dim i As Long 
    For i = 2 To 13 Step 1 
        Range("AH" & i).Value = Application.WorksheetFunction.Sum(Range("C"& i & ":AG" & i)) 
    Next i 
End Sub 
__________________
Regards,
Simon Lloyd
Microsoft Office Help

Want to say thanks? then hit this How to say thanks! button in any post you want to thank
If you find one of my posts helpful then hit this one Helpful Answer in the post that helped most!





1 members found this post helpful.
The Following User Says Thank You to Simon Lloyd For This Useful Post:
streub (9th December 2013)
  #5  
Old 9th December 2013, 10:38
snb's Avatar
snb snb is offline
Forum VIP
MS Office Version: > Office 97
MS Office Skill Level: Interested
 
Join Date: Feb 2011
Location: Europe
Posts: 1,393
Posts Per Day: 0.56
My Top Tip Count: 0
Thanks to others: 0
Thanked 314 Times in 307 Posts
Reputation: 5076 (70) snb has a reputation beyond reputesnb has a reputation beyond reputesnb has a reputation beyond reputesnb has a reputation beyond reputesnb has a reputation beyond reputesnb has a reputation beyond reputesnb has a reputation beyond reputesnb has a reputation beyond reputesnb has a reputation beyond reputesnb has a reputation beyond reputesnb has a reputation beyond repute
Default Re: VBA to sum rows

------ Register to get rid of these "In Post" ads! ------


or even

VBA CODE:
 
Sub M_snb() 
    [AH2:AH13]=[index(sum(C3:AG13),)] 
End Sub 



1 members found this post helpful.
The Following User Says Thank You to snb For This Useful Post:
streub (9th December 2013)
The Code Cage Advertisment
Advertisement

To stop seeing these ads and get other benefits check This page!

 
The Code Cage at Facebookhe Code Cage at Twitter


Tags
rows, sum, vba

Thread Tools
Display Modes 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

Forum Jump

The Code Cage Affilliates



http://www.thecodecage.com/forumz tested by McAfee Security http://www.thecodecage.com/forumz tested by McAfee Security

All times are GMT +1. The time now is 07:41.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Template-Modifications by TMS
No part of this board, functionality or creatives may be copied or reproduced either in part or full without the express permission of The Code Cage Team.
Copyright ©2008 - , Simon lloyd.
We are not associated with nor employed by Microsoft in any way, we simply provide resources!
All MS office icons are registered trademarks of the application they represent and are used with permission from Microsoft
UA-8135493-1
Cultural Forum | Study at Malaysian University
X vBulletin 3.8.7 Debug Information
  • Page Generation 0.18912 seconds
  • Memory Usage 6,478KB
  • Queries Executed 17 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footerEnd
  • (1)ad_footerStart
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_headerEnd
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_leftcolumn_code
  • (1)ad_navbar_below
  • (3)ad_postbit_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (3)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (5)helpful_answers
  • (1)helpfulanswers_javascript
  • (1)navbar
  • (3)navbar_link
  • (3)navbar_noticebit
  • (52)option
  • (5)post_thanks_box
  • (3)post_thanks_box_bit
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (3)post_thanks_postbit
  • (5)post_thanks_postbit_info
  • (5)postbit
  • (5)postbit_ctoptip
  • (5)postbit_onlinestatus
  • (35)postbit_reputation
  • (5)postbit_wrapper
  • (1)showthread_changepostsowner_link
  • (1)showthread_extra_fields
  • (1)showthread_quickreply_mrgdp
  • (1)showthread_reason_popup
  • (1)spacer_close
  • (1)spacer_open
  • (1)su_form
  • (3)tagbit
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_datastore.php
  • ./includes/class_hook.php
  • ./awcoding/plugins/awc.php
  • ./awcoding/plugins/ds.php
  • ./awcoding/plugins/ss.php
  • ./includes/functions_notice.php
  • ./mobiquo/smartbanner.php
  • ./mobiquo/include/classTTConnection.php
  • ./mobiquo/smartbanner/head.inc.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/vbatags.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php
  • ./includes/functions_misc.php 

Hooks Called:
  • init_startup
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_check_criteria
  • notices_noticebit
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • helpfulanswers_showthreadorpost
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • helpfulanswers_show_normal
  • reputation_power
  • reputation_image
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • error_fetch
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • tag_fetchbit
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete