LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Summing user selected records

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!!!

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Summing data on duplicate records? Markl9869 Excel Worksheet Functions 2 November 21st 08 05:29 AM
Summing up Unique Records Isabelle Excel Discussion (Misc queries) 2 June 11th 08 01:30 PM
Trouble identifying selected records richardwo Excel Discussion (Misc queries) 4 January 16th 07 01:48 PM
Summing the # of records matt330 New Users to Excel 1 October 19th 05 04:15 PM
Summing the last records of every month. Richard Buttrey Excel Programming 5 April 2nd 05 10:57 PM


All times are GMT +1. The time now is 06:30 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"