Notifications
Clear all

Digitar data entre um período

2 Posts
2 Usuários
0 Reactions
936 Visualizações
(@neri-s)
Posts: 0
New Member
Topic starter
 

Estou a procura de um comando VBA que aceite digitar somente data entre 01/01/17 e 31/12/17

Tentei fazer assim:

Private Sub txtdata_Exit(ByVal Cancel As MSForms.ReturnBoolean)
        If txtdata.Value < 01/01/2017 or txtdata.Value > 31/12/2017 Then
        txtdata.Value = Date
        MsgBox "data inválida'"
        Cancel = True
        End If
        
 End Sub

como faço? Coloquei também a data entre "" e não funciona

 
Postado : 24/08/2017 7:21 am
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Boa tarde!

Tente algo assim

Private Sub txtdata_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim MyDate As Date
Dim MyDate2 As Date
'Fonte: http://www.globaliconnect.com/excel/index.php?option=com_content&view=article&id=316:excel-vba-date-time-functions-year-month-week-day-functions&catid=79&Itemid=475
MyDate = DateSerial(2017, 1, 1)
MyDate2 = DateSerial(2017, 1, 31)
    If txtdata.Value < MyDate Or txtdata.Value > MyDate2 Then
        MsgBox "A data deve ficar entre '01-31/01/2017' "
    Else
        MsgBox "OK"
    End If
End Sub

Att

 
Postado : 24/08/2017 9:26 am