Summing up user defined results

Hi all - I'm new to VBA programming in Excel and so any help i'd
totally love!


I'm currently writing a function.
Objective: user can select rows (do not have to be sequential). User
clicks on button. UserForm appears with summed results from ONLY rows
that he selected.


What I have now, well it doesn't work:


Sub Button6_Click()
Dim i As Integer
Dim totalNumbers As Integer
Dim aRange As range


For Each a In Selection.Areas
    'MsgBox "Area " & i & " of the selection contains " & _
    '    a.Rows.Count & " rows."
    'call with the selection area and then number of rows
    Call SumValues(a, a.Rows.Count)
    i = i + 1
Next a
End Sub


Public Sub SumValues(a As AcRecord, numberOfRows As Integer)


Dim i As Integer
Dim iRow As Integer


iRow = 6


'set up the column headings


'loop through the recordset


Do While rs.EOF = False
    i = 1


    If Oil = 1 Then
        Call printOrNot("Oil", rs!Oil, i, iRow)
        i = i
    End If


    If Gas = 1 Then
        Call printOrNot("Gas", rs!MCFs, i, iRow)
       i = i
    End If


    If Water = 1 Then
        Call printOrNot("Water", rs!Water, i, iRow)
        i = i
     End If
Loop
End Sub


Public Sub printOrNot(ByRef sumVal As String, rsName As String, ByRef i

As Integer, iRow As Integer)
    If iRow = 6 Then
        'objSheet.Cells(iRow, i) = colHeading
    Else
        sumVal = sumVal + rsName
    End If
    'return this value
End Sub


My spreadsheet has any number of columns as seen in SumValues()
function. So whenever the user selects rows, I just need to sum all of
the columns up on the spreadsheet that he asked to see.


Any help that you guys can give would be so totally appreciated. Thank
you so much in advance!!!

0
12/8/2005 6:08:32 PM
excel 39879 articles. 2 followers. Follow

4 Replies
1065 Views

Similar Articles

[PageSpeed] 54

You would be much better off posting an example of your data table, with the results that you would 
like to see based on the sample.

HTH,
Bernie
MS Excel MVP


<roadie.girl@gmail.com> wrote in message 
news:1134065312.223333.103540@f14g2000cwb.googlegroups.com...
> Hi all - I'm new to VBA programming in Excel and so any help i'd
> totally love!
>
>
> I'm currently writing a function.
> Objective: user can select rows (do not have to be sequential). User
> clicks on button. UserForm appears with summed results from ONLY rows
> that he selected.
>
>
> What I have now, well it doesn't work:
>
>
> Sub Button6_Click()
> Dim i As Integer
> Dim totalNumbers As Integer
> Dim aRange As range
>
>
> For Each a In Selection.Areas
>    'MsgBox "Area " & i & " of the selection contains " & _
>    '    a.Rows.Count & " rows."
>    'call with the selection area and then number of rows
>    Call SumValues(a, a.Rows.Count)
>    i = i + 1
> Next a
> End Sub
>
>
> Public Sub SumValues(a As AcRecord, numberOfRows As Integer)
>
>
> Dim i As Integer
> Dim iRow As Integer
>
>
> iRow = 6
>
>
> 'set up the column headings
>
>
> 'loop through the recordset
>
>
> Do While rs.EOF = False
>    i = 1
>
>
>    If Oil = 1 Then
>        Call printOrNot("Oil", rs!Oil, i, iRow)
>        i = i
>    End If
>
>
>    If Gas = 1 Then
>        Call printOrNot("Gas", rs!MCFs, i, iRow)
>       i = i
>    End If
>
>
>    If Water = 1 Then
>        Call printOrNot("Water", rs!Water, i, iRow)
>        i = i
>     End If
> Loop
> End Sub
>
>
> Public Sub printOrNot(ByRef sumVal As String, rsName As String, ByRef i
>
> As Integer, iRow As Integer)
>    If iRow = 6 Then
>        'objSheet.Cells(iRow, i) = colHeading
>    Else
>        sumVal = sumVal + rsName
>    End If
>    'return this value
> End Sub
>
>
> My spreadsheet has any number of columns as seen in SumValues()
> function. So whenever the user selects rows, I just need to sum all of
> the columns up on the spreadsheet that he asked to see.
>
>
> Any help that you guys can give would be so totally appreciated. Thank
> you so much in advance!!!
> 


0
Bernie
12/8/2005 6:27:57 PM
sample dataset
---------------------------------
row  ---    name      -----     oil     -----     gas     -----
water
A            Church Creek     50             100                20
B            Gulch                25              200               17
C            Cherry               57             157                 13

So if my user selects row A and row C, it should appear as
oil: 157
gas: 257
water: 33

i can't use the status bar to do this, because as far as my knowedge
takes me, it just sums all of these numbers up into one lump sum.

thanks,
rebekah

0
12/8/2005 7:06:24 PM
rebekah,

Try this version:

Sub Button6_Click()

Dim myArea As Range
Dim myCell As Range
Dim i As Integer
Dim ColStart As Integer
Dim ColCount As Integer
Dim RowStart As Integer
Dim myVals(1 To 255) As Double

For Each myArea In Selection
For Each myCell In Intersect(myArea.EntireRow, myArea.CurrentRegion)
 If IsNumeric(myCell.Value) Then
   myVals(myCell.Column) = myVals(myCell.Column) + myCell.Value
   End If
Next myCell
Next myArea

ColStart = Selection.CurrentRegion.Cells(1, 1).Column
ColCount = Selection.CurrentRegion.Columns.Count
RowStart = Selection.CurrentRegion.Cells(1, 1).Row
For i = ColStart + 1 To ColStart + ColCount - 1
MsgBox "The total " & Cells(RowStart, i).Value & " is " & myVals(i)
Next i

End Sub


-- 
HTH,
Bernie
MS Excel MVP


<roadie.girl@gmail.com> wrote in message 
news:1134068784.142772.218140@o13g2000cwo.googlegroups.com...
> sample dataset
> ---------------------------------
> row  ---    name      -----     oil     -----     gas     -----
> water
> A            Church Creek     50             100                20
> B            Gulch                25              200               17
> C            Cherry               57             157                 13
>
> So if my user selects row A and row C, it should appear as
> oil: 157
> gas: 257
> water: 33
>
> i can't use the status bar to do this, because as far as my knowedge
> takes me, it just sums all of these numbers up into one lump sum.
>
> thanks,
> rebekah
> 


0
Bernie
12/8/2005 7:29:23 PM
thanks so much Bernie - that's definitely what i needed and it works
wonderfully! thanks again!, rebekah

0
12/8/2005 7:42:56 PM
Reply:

Similar Artilces:

Reminder
What is Happening? Microsoft is responding to a nebulous 'Evolution of Community' concept, and rejecting the voice of its customers. As the earth was destroyed in "The Hitchhiker's Guide to the Galaxy" to make way for a new 'hyperspace bypass', so newsgroups will be obliterated to make way for the newer 'forums'. Why? Who knows? It's part of 'a bigger agenda' to which us common little people are not privy. Our role is simply to lap up the propaganda in favour of the forums and keep quiet like good little users. ...

How to perform sum sum sum...
How to perform sumation within that particular item but the item is not unique...means item 1 has its own quantity and same goes to item 2...but in the same table... -- Message posted via http://www.accessmonster.com On Tue, 17 Apr 2007 05:28:12 GMT, "EMILYTAN via AccessMonster.com" <u33296@uwe> wrote: >How to perform sumation within that particular item but the item is not >unique...means item 1 has its own quantity and same goes to item 2...but in >the same table... Group By the item. For a more detailed answer, please post a more detailed question (with a des...

Multiple variables to sort and sum, return values<0 with sum refer
Can anyone help me with this one please? I have this table of data. I'd like to be able to write a formula(s) which sums the No according to date and code, but then only returns a sum value (with the code and date in the two adjacent cells) if there is a value greater than 0. Code Ref No Date 1 G/032/05/999 400600 212 19/03/2010 2 G/032/03/001/999 400500 50 19/03/2010 3 G/032/02/001/001 400400 170 19/03/2010 4 G/032/05/999 400600 315 19/03/2010 5 G/032/03/001/999 400500 300 19/03/2010 6 G/032/05/999 400600 202 19/03/2010 7 G/032/03/001/002 40...

Deleting User Accounts
When a user account is deleted in the application of DYN GP, does the database account need to remain in the database or can it be deleted? If it needs to remain on the database, can the rights be changed to a db_reader instead of db_writer? For GP versions 9.0 and later, deleting the user in GP should also delete the SQL user. For earlier versions, it's possible to delete one without the other depending on your settings. In either case though, nothing in GP needs the SQL user to remain there, so unless you have some reporting or other products using that SQL login, you can dele...

Add exchange user
Hello Can anyone help with this problem. Reciently the exchange mailbox store databases crashed and I have replaced it with a new mail box store. However one client do not want to reconnect the user mailbox. When I try to add the user it tells me the operation failed. Thanks If I were you, I would ask this in the Exchange newsgroup: http://www.microsoft.com/technet/community/newsgroups/dgbrowser/en-us/default.mspx?dg=microsoft.public.exchange.admin -- Kathleen Orland - MVP Outlook Outlook Tips: http://www.outlook-tips.net/ http://www.howto-outlook.com/ "Zakaria" wrot...

Summing up user defined results
Hi all - I'm new to VBA programming in Excel and so any help i'd totally love! I'm currently writing a function. Objective: user can select rows (do not have to be sequential). User clicks on button. UserForm appears with summed results from ONLY rows that he selected. What I have now, well it doesn't work: Sub Button6_Click() Dim i As Integer Dim totalNumbers As Integer Dim aRange As range For Each a In Selection.Areas 'MsgBox "Area " & i & " of the selection contains " & _ ' a.Rows.Count & " rows." &...

sum subform to form
=Sum([Forms]![frmCamPledgeList].[frmCamPledgeListSub].[Amount Pledged]) Form (frmCamPledgeList) with subform frmCamPledgeListSub). Subform has a field named Pledge Amount. I want to put a field on the form that gives me a total of the subform's Amount Pledged. I have tried the above, but I get an #error in the unbound text box. Do you need any more info? Any thoughts on why this does not work? Thanks in advance, Scott -- Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/Forums.aspx/access-forms/200912/1 The proper syntax is =Sum([Forms]![frmCa...

Users cannot create appointments
Hi everyone We have recently updated CRM to 3.0. Since the upgrade, everything is working ok but for one little problem. I have users in one particular BU that cannot create appointments. Users in all other BUs do not experience this problem. Also, if a move a user out of this BU, he will be able to create appointments. I have rollup 2 applied. Clues anyone? Thanks! -- GVerreault Well I'm sure you've already deduced that the issue is security related. what is the error they get? can you describe the organization/BU structure in your CRM? You said that if you move a user f...

Exchange Tasks missing from Active Directory Users and Computers
I've been trying to migrate from an old NT domain with an Exchange 5.5 server to a new active directory with an Exchange 2000 server. Actually, we're already half-migrated between the old domain and the active directory (i.e. some of our accounts were previously moved into active directory via ADMT). I was told to go ahead and setup the new email and get the people already in the active directory using the new Exchange server. I initially tried to use the ADC for the old domain and put the two Exchange servers in the same organization after establishing a two-way trust between the doma...

Calculate sum of a field within the query
I have a query that returns the details for a failure record during a specified time period. Where if I search between 1/1/08 and 1/31/08 the query returns the records of all failure records during that period. The row shows the part number and the total parts failed for that record. I need the query to then sum the total part failures for the previous 12 months. So I would see the following: Record # | part # | parts failed | Origination Date| Total Parts failed past 12 months 44444 | x | 4 | 1/2/08 | 200 44445 | Y |1 ...

BES User cannot send emails
Our CEO is unable to send emails, though he can receive them. We are using BES 4 and have another 5 users on that server, which dont seem to have this issue. Called Cingular about this and they say its not on their end. So I removed him from the BES and readded him... Would that be the right path to take? I assume his BES will reininialize and sync up again this way perhaps? Advise? are you certain the BES account has "send as" permissions on his mailbox? -- Susan Conkey [MVP] "Choche" <Christopher.Hoche@gmail.com> wrote in message news:1155571175.890277.13...

how to make this work if sum=5+n2 then sum becomes the value of s.
I want to get or create a formula in excel or access that allows me to keep a running total of my supplies ie... I have 2 pens, remove one and receive 2. answer in the cell becomes 3 pens then if I zero out the received cell the inventory cell still remembers that I have 3 pens not 4 pens (because I received 2 more pens) and visa versa when I zero out the received cell it remembers I have 3 pens not 1 pen(because I removed 1 pen) I believe the method you suggest is flawed. You have no audit trail. If the number on the sheet doesn't match your actual inventory, how will you figure out...

=SUM Ranges Do Not Update
I have a Excel 2000 spread sheet, with the following macro to insert new row. Sub InsertRow() ' ' Macro1 Macro ' Macro recorded 4/27/2004 ' 'GoTo label, MyString ActiveSheet.Unprotect Application.Goto Reference:="MyCell" ActiveCell.Select ActiveCell.EntireRow.Insert ActiveCell.Offset(-1, 0).Select ActiveCell.EntireRow.Copy ActiveCell.Offset(1, 0).Select ActiveCell.PasteSpecial xlPasteAll Application.CutCopyMode = False ActiveCell.Select ActiveSheet.Protect DrawingObjects:=True, Contents:=True Scenarios:=True End Sub The problem is that in the "Mycell&qu...

Sum value between dates problem driving me mad!
Good Evening All, I am really struggling here, have tried, nested IF's including AND's but am a bit stumped. I am fairly familiar with Arrays, but cannot seem to combine all. I have a data table (as detailed below). (Hopefully, this should be 'pastable' into Excel - it works for me) I simply wish to calculate the expected totals per month. Any help & assistance with this would be most welcome. Cheers, Mathew Note, earliest Start is 01/04/03 Start Finish Day Rate Apr-2003 May-2003 Jun-2003 Jul-2003 Aug-2003 01/04/2003 23.00 01/04/2003 09/07/2003 23.00 ...

Picking contacts from multiple users
Hi SBS 2003/Exchange 2003 with outlook 2003/2007 clients. Periodically I need to extract contacts our of multiple users' contacts and de-duplicate them into a final list. What is the mechanism I can use to achieve this? Thanks Regards You can import everything into an Excel or Access database and filter from there, or copy everything into a new Contacts folder in Outlook and use a duplicate remover tool. See http://howto-outlook.com/tag/duplicate-removers -- Robert Sparnaaij [MVP-Outlook] Coauthor, Configuring Microsoft Outlook 2003 http://www.howto-outlook.com/ Outlook FAQ, H...

Connect Mailbox to a Different User
I have User A that has a mailbox. I have User B that has no mailbox. At the moment both A and B can use A's mailbox. I want to disconnect the mailbox from A and connect it to B's account, not just have B able to use the mailbox. How do I do this? Thanks. Make sure you retention set on the mailbox store. http://support.microsoft.com/default.aspx?scid=kb;en-us;274343 Dont be fooled by the title of this KB, you need to delete the mailbox first. On Wed, 23 Feb 2005 14:17:04 -0800, NDaveZ <NDaveZ@discussions.microsoft.com> wrote: >I have User A that has a mailbox. >I ha...

User settings and config files
This is not exactly a C# question by my app is in C# and I'm new to .Net. In my development and testing cycle I frequently must delete folders similar to "C:\Documents and Settings\user\Local Settings\Application Data\company\program.vshost.exe*". I'm afraid this may become a problem after deployment too. How do I deal with these user settings files? One version of my app is deployed with only the default settings. The same version may be deployed a second or third time on the same PC but with program.exe.config files containing settings that override the defau...

Conditional Sum Wizard
Currently I am setting up a sheet and I am using the conditional sum wizard for formulas. Once a formula is created the sytem won't let me copy or change a formula. If I try to copy (Copy, paste special) a formula to another cell, the formula won't work anymore. If I create a formula with the wizard and afterwards change one of the parameters, the formula does not work anymore. Can anyone give me a hint on how I can solve these issues? Thanks. Please don't multi-post - you have an answer elsewhere, relating to use of CSE. Pete On Jan 6, 9:23=A0am, MarcoKoenders <MarcoKo...

Delete Users
hi, Does anyone know how to delete a user? I see the "disable" option, but no delete? thanks You can't delete persons. From a Microsoft CRM point of view, this is correct (reporting). "Kim Lund" <klund01@comcast.net> wrote in message news:OouwwnLyEHA.1192@tk2msftngp13.phx.gbl... > hi, > Does anyone know how to delete a user? I see the "disable" option, but no > delete? > > thanks > It is not possible to Delete a CRM user - this is a design feature. The process would be to: 1. Revoke the users license (so you can reuse i...

Sum Question
I am using Excel 2000 I have the following very simple formula in column j Sheet1 =SUM(B5*H5) I have this copied all the way down to line 40. It shows 0 in all of the cells all the way down. I would like for there to be a way that the cell would not show anything in it UNLESS there was something that it was calculating. For example. I have entered data in column b and column h through line 10, but it still shows 0 in column J all the way down to line 40. I realize that it is showing these 0's b/c I have placed the formula there, but is there a way that it will still calculate but only ...

DOMAIN\user and LOCAL\user are same persons and want to share a profile on local machine.
Hi Folks, I have a case where the same person is a member of two domains: DOMAIN\user and LOCAL\user. I have modified the registry so the profile list for both now identifies "C:\Documents and Settings\user" as the path and I have modified the permissions on "C:\...\user" so the DOMAIN\user and LOCAL\user have the same permissions. DOMAIN\user is NOT a roaming profile user, but has been in the past and was created before LOCAL\user. LOCAL\user is a local user on the machine, and is the same person as DOMAIN\user and would like access to the same profile....

Sum sum sum
Let me describe my problem... I have a form with with item number with is unique and then i put another form (subform) to linked to record the number of item in and out.... This means a item can have many in and out transactions which make the item number not unique.. My problem is I want to calculate the sum of in quantity within the same item. I want the sum to be keep on increasing when the user enter the quantity. Example user key in 2 then new user key 4 and i want the total quantity to be 6... Please help.... No idea of what i am talking? I will explain... -- Message posted via http:/...

User Form
I've made a simple data entry user form that upon clicking a command button ('OK'), puts the values in various places in my worksheet. The userform also has two option buttons. On my worksheet, I have two option buttons. How can I link the option buttons on the user form to the option buttons on the worksheet? ie, when a Userform option button is selected, the worksheet option button is also selected (upon clicking the command (OK) button Hope I explained this well Private Sub CommandButton1_Click() With Sheet1 If OptionButton1.Value = True Then ...

MAC Users
I'm teaching an Excel Intro (Office 2000) in March and I have 3 MAC users in the class. I'd like to provide them with a printout of the differences between Excel for Windows and Excel for MACs, such as keyboard shortcuts, etc. I searched the Microsoft Knowledge Base and Excel Help, but didn't find much I could use. Any ideas? Thanks! Eva Shanley - > I'm teaching an Excel Intro (Office 2000) in March and I have 3 MAC users in the class. I'd like to provide them with a printout of the differences between Excel for Windows and Excel for MACs, such as keyboard ...

Taking sum of a field from sub report
Hi On a sub report I have a field datetot which is the sum of two fields those two fields are in turn coming from two further sub reports of the sub report. How can I take the sum of datetot field to the main report? Thanks Regards See: Bring the total from a subreport onto a main report at: http://allenbrowne.com/casu-18.html -- Allen Browne - Microsoft MVP. Perth, Western Australia Tips for Access users - http://allenbrowne.com/tips.html Reply to group, rather than allenbrowne at mvps dot org. "John" <John@nospam.infovis.co.uk> wrote in message news:OCWbU...