PDA

View Full Version : Label Calculation



av8tordude
02-15-2011, 12:34 PM
I have 2 userform labels (TDay & LDay). Can someone assist in a code that will subtract LDay from TDay and display the results in RDay, which is also a userform label. Thank you for your assistance

mdmackillop
02-15-2011, 12:45 PM
Convert the captions to numbers
Label3.Caption = CLng(Label1.Caption) + CLng(Label2.Caption)

av8tordude
02-15-2011, 01:00 PM
I forgot to mention, the labels caption display time format. Can you assist. thanks

mdmackillop
02-15-2011, 01:10 PM
Try
Label3.Caption = Format(TimeValue(Label1.Caption) - TimeValue(Label2.Caption), "hh:mm")

av8tordude
02-15-2011, 01:22 PM
For some reason, i'm getting a type mismatch.

here is what I have. the various cells have numbers that are time formated. When the userform is displayed, I had to display the time that is in cell as a text so that it can display in a label as (i.e. 32hr & 52min (32:52)).

LDay = Range("AF2").Text
TDay = Range("AF3").Text
RDay.Caption = Format(TimeValue(TDay.Caption) - TimeValue(LDay.Caption), "hh:mm")

mdmackillop
02-15-2011, 01:28 PM
Can you post a workbook with a simple userform showing your label data?

av8tordude
02-15-2011, 01:42 PM
See Attached

mdmackillop
02-15-2011, 01:57 PM
This can probably be simplified, but TimeValue won't work with such numbers

Private Sub CommandButton1_Click()

x = Label1.Caption
t1 = Split(x, ":")(0) / 24 + Split(x, ":")(1) / 24 / 60
y = Label2.Caption
t2 = Split(y, ":")(0) / 24 + Split(y, ":")(1) / 24 / 60

t = 24 * (t2 - t1)
Label3.Caption = Int(t) & ":" & Format((t - Int(t)) * 60, "00")
End Sub

av8tordude
02-15-2011, 02:03 PM
ok...I'll give it a try