I'm not sure what you're doing or where your controls are...
But I guessed that the textboxes (from the Control toolbox toolbar) were on the
same worksheet as the label.
I put 13 textboxes on a worksheet, a label and a commandbutton (all from the
control toolbox toolbar).
This is the code under the commandbutton:
Option Explicit
Private Sub CommandButton1_Click()
Dim iCtr As Long
Dim myTBSum As Double
Dim myTBVal As String
myTBSum = 0
For iCtr = 1 To 13
myTBVal = Me.OLEObjects("Textbox" & iCtr).Object.Value
If IsNumeric(myTBVal) Then
myTBSum = myTBSum + myTBVal
Else
Beep
End If
Next iCtr
Me.Label1.Caption = Format(myTBSum, "0.00")
End Sub
Maybe it'll give you an idea???
Jennifer wrote:
>
> Thanks a bunch-
> Close but I am getting a few errors in getting those I tried to problem
> solve the best I understand and this is where I am stuck: Thank you a bunch!
>
> Dim Ration As Variant
> Dim Percent As String
>
> With Worksheets("Database")
> Ration = txtRFID.Value
> 'Sheets("Rations").Activate
> Percent = WorksheetFunction. _
> SumIf(Range("ProduceItemDatabase"), Ration, Range("BxsToMarket"))
> TBarr = Array(TextBox1, TextBox2, TextBox3, TextBox4, TextBox5, _
> TextBox6, TextBox7, TextBox8, TextBox9, TextBox10, TextBox11, _
> TextBox12, TextBox13)
> For i = 0 To 12
> If Me.TextBox1.Value = "" Then
> Exit Sub
> Else
> Me.lblTotal = Percent - TBarr(i).Value ********It is saying
> type mismatch
> End If
> Next
> End With
> End Sub--
> Thank you,
>
> Jennifer
>
> "JLGWhiz" wrote:
>
> > Already see one goof. Should be For i = 0 To 12 instead of 13.
> > The array is zero based.
> >
> > "Jennifer" wrote:
> >
> > > Hi Guys,
> > > Can you help?
> > > I have created this code but I have never created a loop before so I need
> > > some direction:
> > > I have 13 text boxes I need it to check for a value and subtract it from the
> > > 'percent'
> > > Thank you, Jennifer
> > >
> > > Private Sub GetSum1()
> > > Dim Ration As Variant
> > > Dim Percent As String
> > > With Worksheets("Database")
> > > Ration = txtRFID.Value
> > > 'Sheets("Rations").Activate
> > > Percent = WorksheetFunction. _
> > > SumIf(Range("ProduceItemDatabase"), Ration, Range("BxsToMarket"))
> > > If Me.TextBox1 = "" Then
> > > Exit Sub
> > > Else
> > > Me.lblTotal = Percent - TextBox1.Value
> > > End If
> > >
> > > End With
> > > End Sub
> > >
> > > --
> > > Thank you,
> > >
> > > Jennifer
--
Dave Peterson
|