1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
| Option Compare Text
Dim f, TblClé(), nbCol, ligneEnreg, colCle
Private Sub UserForm_Initialize()
Set f = Sheets("BD")
colCle = 1 ' adapter
nbCol = f.[iv1].End(xlToLeft).Column
For k = nbCol + 1 To 26: Me("textbox" & k).Visible = False: Next k
'--
n = f.[a65000].End(xlUp).Row - 1
Set d = CreateObject("scripting.dictionary")
a = f.Range("a2:a" & f.[a65000].End(xlUp).Row).Offset(, colCle - 1).Value
For i = 1 To UBound(a)
If Not d.exists(a(i, 1)) Then d(a(i, 1)) = i + 1
Next i
ReDim TblClé(1 To d.Count, 1 To 2)
i = 0
For Each c In d.keys
i = i + 1: TblClé(i, 1) = c: TblClé(i, 2) = d(c)
Next c
Call Tri2Col(TblClé, LBound(TblClé), UBound(TblClé))
Me.ComboBox1.List = TblClé
Me.ComboBox1.ListIndex = -1
'-- labels textbox & largeur textbox
For i = 1 To nbCol
Me("textbox" & i).Width = f.Columns(i).Width * 1.1
Set Lab = Me.Controls.Add("Forms.Label.1")
Lab.Caption = f.Cells(1, i)
Lab.Top = Me("textbox" & i).Top + 5
Lab.Left = Me("textbox" & i).Left - 75
x = x + f.Columns(k).Width * 0.5
Next
'For i = nbCol + 1 To 26: Me("textbox" & i).Visible = False: Next
ligneEnreg = f.[a65000].End(xlUp).Row + 1
Me.NoEnreg = ligneEnreg
End Sub
Private Sub ComboBox1_Click()
ligneEnreg = Me.ComboBox1.Column(1)
Me.NoEnreg = ligneEnreg
For Z = 1 To nbCol
Me("textbox" & Z) = f.Cells(ligneEnreg, Z)
Next Z
End Sub
Private Sub B_modif_Click()
If Me.TextBox1 = "" Or ligneEnreg = 0 Then Me.TextBox1.SetFocus: Exit Sub
For k = 1 To nbCol
tmp = Me("TextBox" & k)
If IsNumeric(tmp) Then tmp = CDbl(tmp)
If IsDate(tmp) Then tmp = CDate(tmp)
f.Cells(ligneEnreg, k) = tmp
Next k
raz
ligneEnreg = f.[a65000].End(xlUp).Row + 1
Me.NoEnreg = ligneEnreg
UserForm_Initialize
Me.ComboBox1.ListIndex = -1
Me.ComboBox1.SetFocus
End Sub
Private Sub B_nouv_Click()
ligneEnreg = f.[a65000].End(xlUp).Row + 1
raz
Me.NoEnreg = ligneEnreg
Me.TextBox1.SetFocus
End Sub
Private Sub B_sup_Click()
If MsgBox("Etes vous sûr de suppimer " & Me.TextBox1 & "?", vbYesNo) = vbYes Then
f.Cells(ligneEnreg, 1).Resize(, nbCol).Delete Shift:=xlUp
raz
UserForm_Initialize
End If
End Sub
Sub raz()
Dim c As Control
For Each c In Me.Controls
Select Case TypeName(c)
Case "TextBox"
c.Value = ""
End Select
Next c
End Sub |
Partager