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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
| Dim f, nbCol, pointeur, ligne
Private Sub Label1_Click()
End Sub
Private Sub UserForm_Initialize()
Set f = Sheets("Donnees")
'Donnees est le nom de ma feuille où se trouve mon tableau
ligne = 2
nbCol = f.[A1].CurrentRegion.Columns.Count
x = 20
y = 25
For I = 1 To nbCol
retour = Me.Controls.Add("Forms.Label.1", "Label" & I, True)
Me("label" & I).Caption = f.Cells(2, I)
Me("label" & I).Top = y
Me("label" & I).Left = x
retour = Me.Controls.Add("Forms.TextBox.1", "TextBox" & I, True)
Me("textbox" & I).Top = y
Me("textbox" & I).Left = x + 160
Me("textbox" & I).Width = f.Columns(I).Width + 20
Me("textbox" & I).Value = f.Cells(ligne, I)
y = y + 20
Next
retour = Me.Controls.Add("Forms.Label.1", "Label" & I, True)
Me("label" & I).Caption = f.Cells(1, 1)
Me("label" & I).Top = Me.ListBox1.Top - 10
Me("label" & I).Left = Me.ListBox1.Left + 30
'--
For I = 2 To f.[A65000].End(xlUp).Row
Me.ListBox1.AddItem
Me.ListBox1.List(I - 2, 0) = f.Cells(I, 1)
Me.ListBox1.List(I - 2, 1) = I
Next
pointeur = 1
If nbCol > 8 Then Me.Height = y + 30
pointeur = 0
ligne = Me.ListBox1.List(pointeur, 1)
affiche
End Sub
Private Sub ListBox1_Click()
ligne = Me.ListBox1.Column(1)
pointeur = Me.ListBox1.ListIndex
affiche
End Sub
Private Sub b_suiv_Click()
If pointeur < Me.ListBox1.ListCount - 1 Then
pointeur = pointeur + 1
ligne = Me.ListBox1.List(pointeur, 1)
affiche
End If
End Sub
Private Sub b_prec_Click()
If pointeur > 0 Then
pointeur = pointeur - 1
ligne = Me.ListBox1.List(pointeur, 1)
affiche
End If
End Sub
Private Sub b_premier_Click()
pointeur = 0
ligne = Me.ListBox1.List(pointeur, 1)
affiche
End Sub
Private Sub b_dernier_Click()
pointeur = Me.ListBox1.ListCount - 1
ligne = Me.ListBox1.List(pointeur, 1)
affiche
End Sub
Private Sub B_ok_Click()
Me.ListBox1.Clear
I = 0
Set plage = f.[A1].CurrentRegion
Set c = plage.Find(Me.MotCle, , , xlPart)
If Not c Is Nothing Then
premier = c.Address
Do
Me.ListBox1.AddItem
lig = c.Row
Me.ListBox1.List(I, 0) = plage.Cells(lig, 1)
Me.ListBox1.List(I, 1) = lig
I = I + 1
Set c = plage.FindNext(c)
Loop While Not c Is Nothing And c.Address <> premier
End If
pointeur = 0
ligne = Me.ListBox1.List(pointeur, 1)
affiche
End Sub
Private Sub b_tout_Click()
Me.ListBox1.Clear
For I = 2 To f.[A65000].End(xlUp).Row
Me.ListBox1.AddItem
Me.ListBox1.List(I - 2, 0) = f.Cells(I, 1)
Me.ListBox1.List(I - 2, 1) = I
Next
pointeur = 0
ligne = Me.ListBox1.List(pointeur, 1)
affiche
End Sub
Sub affiche()
For I = 1 To nbCol:
Me("textbox" & I).Value = f.Cells(ligne, I)
w = Evaluate("Cell(""format""," & f.Cells(ligne, I).Address & ")")
If Left(w, 1) = "C" Then Me("textbox" & I).Value = Format(f.Cells(ligne, I), "")
Next I
End Sub |
Partager