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
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
Convert the captions to numbers
[VBA]Label3.Caption = CLng(Label1.Caption) + CLng(Label2.Caption)[/VBA]
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'
I forgot to mention, the labels caption display time format. Can you assist. thanks
Try
[VBA]Label3.Caption = Format(TimeValue(Label1.Caption) - TimeValue(Label2.Caption), "hh:mm")
[/VBA]
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'
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)).
[vba] LDay = Range("AF2").Text
TDay = Range("AF3").Text
RDay.Caption = Format(TimeValue(TDay.Caption) - TimeValue(LDay.Caption), "hh:mm")
[/vba]
Can you post a workbook with a simple userform showing your label data?
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'
See Attached
This can probably be simplified, but TimeValue won't work with such numbers
[VBA]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
[/VBA]
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'
ok...I'll give it a try