ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Help with userform labels (https://www.excelbanter.com/excel-programming/387978-help-userform-labels.html)

[email protected]

Help with userform labels
 
I'm trying to create a simple total displayed in a label. Basically, I
have twelve entries for price and quantity. I'm trying to have a label
(label 23 below) show the total as the user fills in the data.

The total label works if all price and quantity fields are filled.

Private Sub q7_Exit(ByVal Cancel As MSForms.ReturnBoolean)

On Error Resume Next
Label19 = q7 * price7

On Error Resume Next
Label23 = ((price1 * q1) + (price2 * q2) + (price3 * q3) + (price4 *
q4) + (price5 * q5) + (price6 * q6) + (price7 * q7) + (price8 * q8) +
(price9 * q9) + (price10 * q10) + (price11 * q11) + (price12 * q12))

End Sub


Thanks


Dave Peterson

Help with userform labels
 
I think I'd use something like:

Private Sub q7_Exit(ByVal Cancel As MSForms.ReturnBoolean)

Dim iCtr as long
dim myTotal as double

mytotal = 0
for ictr = 1 to 12
if isnumeric(me.controls("price" & ictr).value) _
and isnumeric(me.controls("q" & ictr).valuel) then
mytotal = mytotal _
+ (me.controls("price" & ictr) * me.controls("q" & ictr))
end if
next ictr

label23.caption = format(mytotal, "0.00")




On Error Resume Next
Label19 = q7 * price7

On Error Resume Next
Label23 = ((price1 * q1) + (price2 * q2) + (price3 * q3) + (price4 *
q4) + (price5 * q5) + (price6 * q6) + (price7 * q7) + (price8 * q8) +
(price9 * q9) + (price10 * q10) + (price11 * q11) + (price12 * q12))

End Sub

wrote:

I'm trying to create a simple total displayed in a label. Basically, I
have twelve entries for price and quantity. I'm trying to have a label
(label 23 below) show the total as the user fills in the data.

The total label works if all price and quantity fields are filled.

Private Sub q7_Exit(ByVal Cancel As MSForms.ReturnBoolean)

On Error Resume Next
Label19 = q7 * price7

On Error Resume Next
Label23 = ((price1 * q1) + (price2 * q2) + (price3 * q3) + (price4 *
q4) + (price5 * q5) + (price6 * q6) + (price7 * q7) + (price8 * q8) +
(price9 * q9) + (price10 * q10) + (price11 * q11) + (price12 * q12))

End Sub

Thanks


--

Dave Peterson

[email protected]

Help with userform labels
 
Thanks Dave. It works great!
there is a typo on the code below...notice that valuel should be
value.

thanks again
On Apr 23, 11:40 am, Dave Peterson wrote:
I think I'd use something like:

Private Sub q7_Exit(ByVal Cancel As MSForms.ReturnBoolean)

Dim iCtr as long
dim myTotal as double

mytotal = 0
for ictr = 1 to 12
if isnumeric(me.controls("price" & ictr).value) _
and isnumeric(me.controls("q" & ictr).valuel) then
mytotal = mytotal _
+ (me.controls("price" & ictr) * me.controls("q" & ictr))
end if
next ictr

label23.caption = format(mytotal, "0.00")

On Error Resume Next
Label19 = q7 * price7

On Error Resume Next
Label23 = ((price1 * q1) + (price2 * q2) + (price3 * q3) + (price4 *
q4) + (price5 * q5) + (price6 * q6) + (price7 * q7) + (price8 * q8) +
(price9 * q9) + (price10 * q10) + (price11 * q11) + (price12 * q12))

End Sub



wrote:

I'm trying to create a simple total displayed in a label. Basically, I
have twelve entries for price and quantity. I'm trying to have a label
(label 23 below) show the total as the user fills in the data.


The total label works if all price and quantity fields are filled.


Private Sub q7_Exit(ByVal Cancel As MSForms.ReturnBoolean)


On Error Resume Next
Label19 = q7 * price7


On Error Resume Next
Label23 = ((price1 * q1) + (price2 * q2) + (price3 * q3) + (price4 *
q4) + (price5 * q5) + (price6 * q6) + (price7 * q7) + (price8 * q8) +
(price9 * q9) + (price10 * q10) + (price11 * q11) + (price12 * q12))


End Sub


Thanks


--

Dave Peterson




Dave Peterson

Help with userform labels
 
I composed in the email--I should have copied to the VBE and compiled (or given
you a warning!).

But glad you found it.

wrote:

Thanks Dave. It works great!
there is a typo on the code below...notice that valuel should be
value.

thanks again
On Apr 23, 11:40 am, Dave Peterson wrote:
I think I'd use something like:

Private Sub q7_Exit(ByVal Cancel As MSForms.ReturnBoolean)

Dim iCtr as long
dim myTotal as double

mytotal = 0
for ictr = 1 to 12
if isnumeric(me.controls("price" & ictr).value) _
and isnumeric(me.controls("q" & ictr).valuel) then
mytotal = mytotal _
+ (me.controls("price" & ictr) * me.controls("q" & ictr))
end if
next ictr

label23.caption = format(mytotal, "0.00")

On Error Resume Next
Label19 = q7 * price7

On Error Resume Next
Label23 = ((price1 * q1) + (price2 * q2) + (price3 * q3) + (price4 *
q4) + (price5 * q5) + (price6 * q6) + (price7 * q7) + (price8 * q8) +
(price9 * q9) + (price10 * q10) + (price11 * q11) + (price12 * q12))

End Sub



wrote:

I'm trying to create a simple total displayed in a label. Basically, I
have twelve entries for price and quantity. I'm trying to have a label
(label 23 below) show the total as the user fills in the data.


The total label works if all price and quantity fields are filled.


Private Sub q7_Exit(ByVal Cancel As MSForms.ReturnBoolean)


On Error Resume Next
Label19 = q7 * price7


On Error Resume Next
Label23 = ((price1 * q1) + (price2 * q2) + (price3 * q3) + (price4 *
q4) + (price5 * q5) + (price6 * q6) + (price7 * q7) + (price8 * q8) +
(price9 * q9) + (price10 * q10) + (price11 * q11) + (price12 * q12))


End Sub


Thanks


--

Dave Peterson


--

Dave Peterson


All times are GMT +1. The time now is 10:38 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com