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
   |  
Dim f, nbCol, pointeur, ligne
Private Sub UserForm_Initialize()
  Set f = Sheets("BD")
  ligne = 2
  nbCol = f.[A1].CurrentRegion.Columns.Count
  x = 11
  y = 15
  For i = 1 To nbCol
    retour = Me.Controls.Add("Forms.Label.1", "Label" & i, True)
    Me("label" & i).Caption = f.Cells(1, 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 + 30
    Me("textbox" & i).Width = f.Columns(i).Width + 4
    '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 + 2
  '--
  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), "0000.00 ")
  Next i
End Sub | 
Partager