I need date to be displayed in userform label however date must be taken from a cell and must change at 24 mark [ see the image below]
. Please help
https://imgur.com/JZ0cRUD
https://imgur.com/JZ0cRUD
Private Sub UserForm_Activate()
Dim dCell As Range
For Each dCell In Sheet1.Range("B:B") 'Range must be time range only or add a isdate(dCell)=true
If dCell > TimeValue("23:59:59") Then
dCell.Select
Label1.Caption = CStr(dCell.Offset(0, -1).Value)
Exit For
Else
'Handle Error
End If
Next dCell
End Sub
[LEFT][COLOR=#222222][FONT=Verdana][h]:00 [/FONT][/COLOR][/LEFT]
[LEFT][COLOR=#333333][FONT=monospace] If dCell > TimeValue("23:59:59") Then[/FONT][/COLOR][/LEFT]
if dCell=Range(A1)
[LEFT][COLOR=#333333][FONT=monospace]Private Sub UserForm_Activate()
Label1.Caption = [COLOR=#222222][FONT=Verdana]Cstr(Range("A4").End(xlDown))[/FONT][/COLOR]
End Sub[/FONT][/COLOR][/LEFT]
[COLOR=#333333][FONT=monospace]Private Sub UserForm_Activate()
Dim I as long
I=5
Do until cells(1,i).value <>""
i=i+1
Loop
Label1.Caption = [COLOR=#222222][FONT=Verdana]cstr(cells(1,i).value)[/FONT][/COLOR]
End Sub[/FONT][/COLOR]
Label1.Caption = Format(Cells(1,i).Value, "h:mm AM/PM")
Rather than going through CStr, have you looked at using the Format function.
Code:Label1.Caption = Format(Cells(1,i).Value, "h:mm AM/PM")
[LEFT][COLOR=#222222][FONT=Verdana]Label1.Caption =[/FONT][/COLOR][COLOR=#222222][FONT=Verdana] [/FONT][/COLOR][COLOR=#222222][FONT=Verdana]Format(cells(1,i),"Short Date")[/FONT][/COLOR][/LEFT]
[LEFT][COLOR=#222222][FONT=Verdana][/FONT][/COLOR][COLOR=#222222][FONT=Verdana][LEFT][COLOR=#222222][FONT=Verdana]Format(cells(1,i),"dd/mm/yy")[/FONT][/COLOR][/LEFT][/FONT][/COLOR][/LEFT]
Any reason to prefer Format to CStr?