PC Review


Reply
Thread Tools Rate Thread

Adding Label Numerical Values correctly

 
 
Corey ....
Guest
Posts: n/a
 
      25th Jul 2008
I am trying to ADD the values of 3 label Caption IF they are a Numerical
Value.
I have used the LONG approach below, but it only works on the provision that
the user starts at the label63 then to the Label74 and thirdly to the
Label87.
But if the user starts at label74 or Label87, the below code does not add
the values and place the result into Textbox64.

How can i better code this to allow for ALL not matter what Labels are
numerical, and total the values in TextBox64, without having to add every
possible combinatiopn of the current code i have ?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If IsNumeric(Label63.Caption) = True And IsNumeric(Label74.Caption) = False
And IsNumeric(Label87.Caption) = False Then TextBox64.Value =
Val(Label63.Caption)
If IsNumeric(Label63.Caption) = True And IsNumeric(Label74.Caption) = True
And IsNumeric(Label87.Caption) = False Then TextBox64.Value =
Val((Label63.Caption)) + Val((Label74.Caption))
If IsNumeric(Label63.Caption) = True And IsNumeric(Label74.Caption) = True
And IsNumeric(Label87.Caption) = True Then TextBox64.Value =
Val((Label63.Caption)) + Val((Label74.Caption)) + Val((Label87.Caption))
TextBox64 = Format(TextBox64, "0.00")
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


CtM.


 
Reply With Quote
 
 
 
 
Corey ....
Guest
Posts: n/a
 
      25th Jul 2008
TextBox64 = Val(Label63) + Val(Label74) + Val(Label87)
TextBox64 = Format(TextBox64, "0.00")
Done the job.

Thanks Corey.

No worreis mate.

Corey....
:-)
"Corey ...." <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I am trying to ADD the values of 3 label Caption IF they are a Numerical
>Value.
> I have used the LONG approach below, but it only works on the provision
> that the user starts at the label63 then to the Label74 and thirdly to the
> Label87.
> But if the user starts at label74 or Label87, the below code does not add
> the values and place the result into Textbox64.
>
> How can i better code this to allow for ALL not matter what Labels are
> numerical, and total the values in TextBox64, without having to add every
> possible combinatiopn of the current code i have ?
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> If IsNumeric(Label63.Caption) = True And IsNumeric(Label74.Caption) =
> False And IsNumeric(Label87.Caption) = False Then TextBox64.Value =
> Val(Label63.Caption)
> If IsNumeric(Label63.Caption) = True And IsNumeric(Label74.Caption) = True
> And IsNumeric(Label87.Caption) = False Then TextBox64.Value =
> Val((Label63.Caption)) + Val((Label74.Caption))
> If IsNumeric(Label63.Caption) = True And IsNumeric(Label74.Caption) = True
> And IsNumeric(Label87.Caption) = True Then TextBox64.Value =
> Val((Label63.Caption)) + Val((Label74.Caption)) + Val((Label87.Caption))
> TextBox64 = Format(TextBox64, "0.00")
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
>
> CtM.
>



 
Reply With Quote
 
OssieMac
Guest
Posts: n/a
 
      25th Jul 2008
Not sure if I have interpreted you question correctly. it appears that you
want to sum the label captions if they are numeric. If this is correct, the
the following should do the trick.

I have used ActiveSheet for the labels. You might need to change this if the
labels are on a Userform.

Sub test()

Dim lngSum As Long

lngSum = 0 'This line possibly not required depending on your other code

With ActiveSheet
If IsNumeric(.Label63.Caption) = True Then
lngSum = lngSum + .Label63.Caption
End If

If IsNumeric(.Label74.Caption) = True Then
lngSum = lngSum + .Label74.Caption
End If

If IsNumeric(.Label87.Caption) = True Then
lngSum = lngSum + .Label87.Caption
End If

.TextBox64 = Format(lngSum, "0.00")
End With

End Sub
--
Regards,

OssieMac


"Corey ...." wrote:

> I am trying to ADD the values of 3 label Caption IF they are a Numerical
> Value.
> I have used the LONG approach below, but it only works on the provision that
> the user starts at the label63 then to the Label74 and thirdly to the
> Label87.
> But if the user starts at label74 or Label87, the below code does not add
> the values and place the result into Textbox64.
>
> How can i better code this to allow for ALL not matter what Labels are
> numerical, and total the values in TextBox64, without having to add every
> possible combinatiopn of the current code i have ?
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> If IsNumeric(Label63.Caption) = True And IsNumeric(Label74.Caption) = False
> And IsNumeric(Label87.Caption) = False Then TextBox64.Value =
> Val(Label63.Caption)
> If IsNumeric(Label63.Caption) = True And IsNumeric(Label74.Caption) = True
> And IsNumeric(Label87.Caption) = False Then TextBox64.Value =
> Val((Label63.Caption)) + Val((Label74.Caption))
> If IsNumeric(Label63.Caption) = True And IsNumeric(Label74.Caption) = True
> And IsNumeric(Label87.Caption) = True Then TextBox64.Value =
> Val((Label63.Caption)) + Val((Label74.Caption)) + Val((Label87.Caption))
> TextBox64 = Format(TextBox64, "0.00")
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
>
> CtM.
>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Two values not adding correctly chitown29 Microsoft Excel Misc 3 27th May 2010 09:21 PM
problem when adding values in label of gridview Luc Microsoft ASP .NET 0 21st Sep 2009 10:29 PM
Only chart numerical values, not error values =?Utf-8?B?YW5keQ==?= Microsoft Excel Charting 2 8th Nov 2007 10:46 PM
Adding up non numerical values =?Utf-8?B?V29vc3Rlcg==?= Microsoft Excel New Users 3 23rd Sep 2007 01:03 AM
Adding numerical values based on multiple values in another column =?Utf-8?B?S2F6bWFuaWFj?= Microsoft Excel Worksheet Functions 6 4th Apr 2007 08:53 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:41 AM.