Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 385
Default Sum values in listbox

The user chooses from a combo box and it then fills a list box with 6 colomns
that correlate to the combo box.

My question is how do i write a formula to sum the value that show up in
column 4 (percent of ratio) in the listbox. Here is the code that i use to
fill the listbox. i want the sum total to show up in a lable1 when the combo
box is loaded.


Private Sub LoadData()
With lstData
..Clear
Ration = cboRation.Value
For index = 2 To source.Rows.Count
If Ration = source.Cells(index, 6) Then
.AddItem source.Cells(index, 1) 'id
.List(.ListCount - 1, 2) = source.Cells(index, eBoxes.Date1)
.List(.ListCount - 1, 3) = source.Cells(index, eBoxes.Ingredient)
.List(.ListCount - 1, 4) = source.Cells(index, eBoxes.Percent_of_ration)
.List(.ListCount - 1, 5) = source.Cells(index, eBoxes.Ration_ID)
.List(.ListCount - 1, 6) = source.Cells(index, eBoxes.Pounds)
End If
Next
End With


End Sub
--
Thank you,

Jennifer
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Sum values in listbox

Private Sub LoadData()
With lstData
..Clear
Ration = cboRation.Value
Total = 0
For index = 2 To source.Rows.Count
If Ration = source.Cells(index, 6) Then
.AddItem source.Cells(index, 1) 'id
data = source.Cells(index, eBoxes.Date1)
total = total + data
.List(.ListCount - 1, 2) = data
data = source.Cells(index, eBoxes.Ingredient)
total = total + data
.List(.ListCount - 1, 3) = data
data = source.Cells(index, eBoxes.Percent_of_ration)
total = total + data
.List(.ListCount - 1, 4) = data
data = source.Cells(index, eBoxes.Ration_ID)
total = total + data
.List(.ListCount - 1, 5) = data
data = source.Cells(index, eBoxes.Pounds)
total = total + data
.List(.ListCount - 1, 6) = data
End If
Next
End With

End Sub


"Jennifer" wrote:

The user chooses from a combo box and it then fills a list box with 6 colomns
that correlate to the combo box.

My question is how do i write a formula to sum the value that show up in
column 4 (percent of ratio) in the listbox. Here is the code that i use to
fill the listbox. i want the sum total to show up in a lable1 when the combo
box is loaded.


Private Sub LoadData()
With lstData
.Clear
Ration = cboRation.Value
For index = 2 To source.Rows.Count
If Ration = source.Cells(index, 6) Then
.AddItem source.Cells(index, 1) 'id
.List(.ListCount - 1, 2) = source.Cells(index, eBoxes.Date1)
.List(.ListCount - 1, 3) = source.Cells(index, eBoxes.Ingredient)
.List(.ListCount - 1, 4) = source.Cells(index, eBoxes.Percent_of_ration)
.List(.ListCount - 1, 5) = source.Cells(index, eBoxes.Ration_ID)
.List(.ListCount - 1, 6) = source.Cells(index, eBoxes.Pounds)
End If
Next
End With


End Sub
--
Thank you,

Jennifer

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 385
Default Sum values in listbox

I am getting the error varible not defined for "Data" is that because it
should be lstData? When i switch it to lstData then the i get another error
message and something about it being "Null"

I need some help . . . i want to sum column 3 in the listbox and have it
show the sum value in a label. HELP
--
Thank you,

Jennifer


"Joel" wrote:

Private Sub LoadData()
With lstData
.Clear
Ration = cboRation.Value
Total = 0
For index = 2 To source.Rows.Count
If Ration = source.Cells(index, 6) Then
.AddItem source.Cells(index, 1) 'id
data = source.Cells(index, eBoxes.Date1)
total = total + data
.List(.ListCount - 1, 2) = data
data = source.Cells(index, eBoxes.Ingredient)
total = total + data
.List(.ListCount - 1, 3) = data
data = source.Cells(index, eBoxes.Percent_of_ration)
total = total + data
.List(.ListCount - 1, 4) = data
data = source.Cells(index, eBoxes.Ration_ID)
total = total + data
.List(.ListCount - 1, 5) = data
data = source.Cells(index, eBoxes.Pounds)
total = total + data
.List(.ListCount - 1, 6) = data
End If
Next
End With

End Sub


"Jennifer" wrote:

The user chooses from a combo box and it then fills a list box with 6 colomns
that correlate to the combo box.

My question is how do i write a formula to sum the value that show up in
column 4 (percent of ratio) in the listbox. Here is the code that i use to
fill the listbox. i want the sum total to show up in a lable1 when the combo
box is loaded.


Private Sub LoadData()
With lstData
.Clear
Ration = cboRation.Value
For index = 2 To source.Rows.Count
If Ration = source.Cells(index, 6) Then
.AddItem source.Cells(index, 1) 'id
.List(.ListCount - 1, 2) = source.Cells(index, eBoxes.Date1)
.List(.ListCount - 1, 3) = source.Cells(index, eBoxes.Ingredient)
.List(.ListCount - 1, 4) = source.Cells(index, eBoxes.Percent_of_ration)
.List(.ListCount - 1, 5) = source.Cells(index, eBoxes.Ration_ID)
.List(.ListCount - 1, 6) = source.Cells(index, eBoxes.Pounds)
End If
Next
End With


End Sub
--
Thank you,

Jennifer

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Sum values in listbox

The problem is not with "Data". "Data" is only a intermediate variable. The
problem is with your original code. There is a problem with the statement

source.Cells(index, eBoxes.Date1)

I don't know if source or eboxes is defined.



"Jennifer" wrote:

I am getting the error varible not defined for "Data" is that because it
should be lstData? When i switch it to lstData then the i get another error
message and something about it being "Null"

I need some help . . . i want to sum column 3 in the listbox and have it
show the sum value in a label. HELP
--
Thank you,

Jennifer


"Joel" wrote:

Private Sub LoadData()
With lstData
.Clear
Ration = cboRation.Value
Total = 0
For index = 2 To source.Rows.Count
If Ration = source.Cells(index, 6) Then
.AddItem source.Cells(index, 1) 'id
data = source.Cells(index, eBoxes.Date1)
total = total + data
.List(.ListCount - 1, 2) = data
data = source.Cells(index, eBoxes.Ingredient)
total = total + data
.List(.ListCount - 1, 3) = data
data = source.Cells(index, eBoxes.Percent_of_ration)
total = total + data
.List(.ListCount - 1, 4) = data
data = source.Cells(index, eBoxes.Ration_ID)
total = total + data
.List(.ListCount - 1, 5) = data
data = source.Cells(index, eBoxes.Pounds)
total = total + data
.List(.ListCount - 1, 6) = data
End If
Next
End With

End Sub


"Jennifer" wrote:

The user chooses from a combo box and it then fills a list box with 6 colomns
that correlate to the combo box.

My question is how do i write a formula to sum the value that show up in
column 4 (percent of ratio) in the listbox. Here is the code that i use to
fill the listbox. i want the sum total to show up in a lable1 when the combo
box is loaded.


Private Sub LoadData()
With lstData
.Clear
Ration = cboRation.Value
For index = 2 To source.Rows.Count
If Ration = source.Cells(index, 6) Then
.AddItem source.Cells(index, 1) 'id
.List(.ListCount - 1, 2) = source.Cells(index, eBoxes.Date1)
.List(.ListCount - 1, 3) = source.Cells(index, eBoxes.Ingredient)
.List(.ListCount - 1, 4) = source.Cells(index, eBoxes.Percent_of_ration)
.List(.ListCount - 1, 5) = source.Cells(index, eBoxes.Ration_ID)
.List(.ListCount - 1, 6) = source.Cells(index, eBoxes.Pounds)
End If
Next
End With


End Sub
--
Thank you,

Jennifer

Reply
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
Listbox Values Richard Excel Discussion (Misc queries) 3 July 29th 08 12:22 AM
Values from a ListBox CG Rosén Excel Programming 1 September 11th 05 04:32 PM
Fill values into a listbox matching selected values from a combobox Jon[_19_] Excel Programming 4 January 25th 05 04:25 PM
Compare Listbox values with Collection values Stuart[_5_] Excel Programming 2 September 20th 03 01:58 PM
Sorting ListBox results or transposing ListBox values to other cells for sorting Rob[_8_] Excel Programming 1 July 9th 03 04:35 AM


All times are GMT +1. The time now is 05:46 AM.

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"