'Version patricktoulon
Option Explicit
Private Sub CommandButton1_Click() 'quitter
Unload Me
End Sub
Private Sub TbX_Date_Change()
If Len(TbX_Date) = 10 Then refrech CDate(TbX_Date), True
End Sub
Private Sub Valider_Click()
Dim lig As Long
lig = Range("A" & Rows.Count).End(xlUp).Row + 1
Range("A" & lig).Value = CDate(TbX_Date)
Range("B" & lig).Value = Val(Mid(TbX_sem, 2)) ' ou TbX_sem.Value (formaté comme le textbox )
Range("C" & lig).Value = Month(CDate(TbX_Date)) ' ou tbx_mois (formaté comme le textbox )
Range("D" & lig).Value = Val(TbX_an.Value)
Range("E" & lig).Value = Val(TbX_Id.Value)
'on ne onload pas et on ne refait pas un show on rafraichi :)
refrech Date
End Sub
Sub refrech(d As Variant, Optional eventchange As Boolean = False)
'si c'est l'event initialise on met la date sinon on ne touche pas le textbox "TbX_Date"
If Not eventchange Then TbX_Date = IIf(IsDate(d), d, "")
TbX_mois = IIf(IsDate(d), MonthName(Month(d)), "")
TbX_an = IIf(IsDate(d), Year(d), "")
TbX_sem = IIf(IsDate(d), Format(WorksheetFunction.IsoWeekNum(d), "\S00"), "")
TbX_Id = IIf(IsDate(d), Application.Max([e:e]) + 1, "")
End Sub
Private Sub UserForm_Initialize()
refrech Date
End Sub