Thread: Creating a loop
View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.programming
JLGWhiz JLGWhiz is offline
external usenet poster
 
Posts: 3,986
Default Creating a loop

The TBarr(1) should have been TBarr(i). I fixed that in the revised code
that is posted. The type mismatch error is telling you that your variable
"Percent" and the TextBox value are two different data types. One is
probably a string and the other a number. You can try this modified line:

Me.lblTotal = Percent - CDbl(TBarr(i).Value)

The CDbl coerces the TextBox value to a number.


"JLGWhiz" wrote:

Hope this has all the typos cleared. You might have to make the array all on
one line instead of three. Sometimes the attenuation line doesn't work. But
you would know if it turns red when you paste it in.

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"))
TBarr = Array(TextBox1, TextBox2, TextBox3, TextBox4, TextBox5, _
TextBox6, TextBox7, TextBox8, TextBox9, TextBox10, TextBox11, _
TextBox12, TextBox13)
For i = 0 To 12
If Me.TBarr(i)Value = "" Then
Exit Sub
Else
Me.lblTotal = Percent - TBarr(i).Value
End If
Next
End With
End Sub


"Jennifer" wrote:

Hi,
Does there need to be some sort of sum function for the array?
--
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