remplir un userform à partir de ligne dans excel

aeryne

XLDnaute Junior
Bonjour
Je possède un fichier excel et j'aimerai pouvoir remplir des textbox et combobox à partir du fichier.
chaque ligne correspond à un numero de dossier différent et j'aimerai si je choisi un numero de dossier que les informations que je possède sur ce fichier remplissent le userform pour moi pouvoir ensuite modifier les données si elles sont erronées et les renvoyer de nouveau dans le tableau écraser les anciennes données.
Sachant que le tableau est incrémenté régulièrement il dépassera les 1000 lignes sans souci et il possede 65 colonnes.
d'ou le désire de visualiser certaines informations de facon plus pratique.
les numeros de dossier se situent colonne C et mes données commencent colonne B et ligne 2.

voici 2 ébauches différentes par rapport à ce que j'ai trouvé sur le net mais aucunes ne marchent.
Code:
'Private D As Object 'déclare la variable D (onglet Données)
'Private LI As Integer 'déclare la variable LI (Ligne)



'Private Sub UserForm3_Initialize() 'à l'initialisation de l'userForm


'Dim DL As Integer 'décalre la variable DL (Dernière Ligne)
'Dim PL As Range 'déclare la variable PL (PLage)

'Set D = Sheets("AVP") 'définit l'onglet D
'DL = D.Cells(Application.Rows.Count, 3).End(xlUp).Row 'définit la dernière ligne éditée DL de la colonne 1 (=A) de l'onglet D
'Set PL = D.Range("C2:C" & DL) 'définit la plage PL
'Select Case DL 'agit en fonction de la valeur de la dernière Ligne DL
'    Case 2 'cas 2
'        MsgBox "La base de données est vide": End 'message, stoppe toue exécution de code
'    Case 3 'cas 3'alimente la ComboBox1 avec la valeur de la cellule A3
'        Me.ComboBox1.AddItem (D.Range("C2").Value)
'    Case Else 'tous les autres cas
'        Me.ComboBox1.List = PL.Value 'alimente la ComboBox1 avec les valeur de la plage PL
'End Select 'fin de l'action en fonction de...
'End Sub

Private Sub textbox23_Change() 'au changement dans la CombobOx1


'le premier élément d'une Combobox a 0 comme valeur de la prorpiété [ListIndex], le second 1, le troisième 2, etc.
'si il n'y a pas de doublons, (ListIndex + 3) renvoie le numéro de la ligne d l'élément sélectionné
'LI = Me.ComboBox28.ListIndex + 2 'récupère le numéro de ligne de l'élément sélectionné

'rechercher les différentes valeurs saisies dans la base de données
'Me.TextBox1 = D.Cells(LI, 2)
'Me.TextBox3 = D.Cells(LI, 4)
'Me.ComboBox7 = D.Cells(LI, 5)
'Me.ComboBox5 = D.Cells(LI, 8)
'Me.TextBox20 = D.Cells(LI, 17)
'Me.TextBox21 = D.Cells(LI, 19)
'Me.TextBox22 = D.Cells(LI, 20)
'Me.ComboBox7 = D.Cells(LI, 21)
'Me.TextBox18 = D.Cells(LI, 56)
'Me.TextBox19 = D.Cells(LI, 57)
'Me.ComboBox1 = D.Cells(LI, 58)
'Me.ComboBox12 = D.Cells(LI, 59)
'Me.ComboBox13 = D.Cells(LI, 60)
'Me.ComboBox3 = D.Cells(LI, 61)
'Me.ComboBox9 = D.Cells(LI, 62)
'Me.ComboBox4 = D.Cells(LI, 63)

'End Sub


Code:
'Sub UserForm3_activate()
Cells.Find(what:="textbox23.value", after:=ActiveCell, LookIn:=xlFormulas, lookat:=xlPart, searchorder:=xlByRows, searchdirection:=xlNext, MatchCase:=False, searchformat:=False).Activate
TextBox23.Value = Range(ActiveCell).Value
ActiveCell.Offset(0, -1).Select

TextBox1.Value = Range(cell).Value


End Sub

j'ai mi un petit morceau du fichier car il était beaucoup trop important.
j'espère que j'ai été claire dans mes explications et merci d'avance de votre aide ou de vos explications.
 

aeryne

XLDnaute Junior
Re : remplir un userform à partir de ligne dans excel

ton formulaire est très bien d'ailleurs je l'utilise dans un fichier moins compliqué et il fonctionne très bien mais vu toutes les complications de ce fichier ci je me dis que revenir à mon idée de remplir un userform et peut être moins compliqué?
voici le code que j'utilise pour remplir mon tableau à partir de mon userform initial:
Code:
Private Sub ComboBox15_Change()

End Sub

Private Sub ComboBox18_Change()

End Sub

Private Sub ComboBox27_Change()

End Sub

Private Sub ComboBox7_Change()

End Sub

Private Sub CheckBox1_Click()

End Sub

Private Sub ComboBox2_Change()

End Sub

Private Sub CheckBox13_Click()

End Sub

Private Sub ComboBox10_Change()

End Sub

Private Sub ComboBox11_Change()

End Sub

Private Sub ComboBox12_Change()

End Sub

Private Sub ComboBox13_Change()

End Sub

Private Sub ComboBox14_Change()

End Sub

Private Sub ComboBox3_Change()

End Sub

Private Sub ComboBox5_Change()

End Sub

Private Sub ComboBox6_Change()

End Sub

Private Sub CommandButton4_Click()
UserForm1.Hide

End Sub

Private Sub CommandButton5_Click()
Unload UserForm1

End Sub

Private Sub Frame1_Click()

End Sub

Private Sub Frame3_Click()

End Sub

Private Sub Frame7_Click()

End Sub

Private Sub Frame8_Click()

End Sub

Private Sub Label17_Click()

End Sub

Private Sub OptionButton5_Click()

End Sub

Private Sub Label18_Click()

End Sub

Private Sub Label2_Click()

End Sub

Private Sub Label20_Click()

End Sub

Private Sub Label21_Click()

End Sub

Private Sub Label22_Click()

End Sub

Private Sub Label26_Click()

End Sub

Private Sub Label27_Click()

End Sub

Private Sub Label31_Click()

End Sub

Private Sub Label34_Click()

End Sub

Private Sub Label35_Click()

End Sub

Private Sub Label36_Click()

End Sub

Private Sub Label48_Click()

End Sub

Private Sub Label5_Click()

End Sub

Private Sub TextBox16_Change()

End Sub

Private Sub TextBox17_Change()

End Sub

Private Sub TextBox18_Change()

End Sub

Private Sub TextBox21_Change()

End Sub

Private Sub TextBox24_Change()

End Sub

Private Sub TextBox25_Change()

End Sub

Private Sub TextBox28_Change()

End Sub

Private Sub TextBox5_Change()

End Sub

Private Sub TextBox7_Change()

End Sub

Private Sub UserForm_Initialize()
TextBox1.Value = Date
TextBox2 = Format(Now, "yy")
TextBox12.Value = Evaluate("=INT((TODAY()-SUM(MOD(DATE(YEAR(TODAY()-MOD(TODAY()-2,7)+3),1,2),{1E+99;7})*{1;-1})+5)/7)")
TextBox13.Value = 80




Dim Wk2 As Workbook
w = "fichier conservation dossier échantillons Année en cours.xlsm"
On Error Resume Next
Set Wk2 = Workbooks(w)
If Err <> 0 Then
    y = Workbooks("AVP_Année en cours.xlsm").FullName  'recupere le chemin de ton fichier excel genre "C:\documents\PRINCIPAL.xls"
x = Workbooks("AVP_Année en cours.xlsm").Name  'recupere le nom du fichier excel "PRINCIPAL.xls"
lg = Len(x) 'len=longueur
chemin = Mid(y, 1, Len(y) - Len(x)) 'recupere juste le chemin "C:\documents\"
Workbooks.Open (chemin + "fichier conservation dossier échantillons Année en cours.xlsm")
    End If




End Sub



Private Sub CheckBox11_Click()

End Sub
Private Sub TextBox1_Enter()


End Sub

Private Sub TextBox2_Enter()

End Sub

Private Sub Textbox12_enter()


End Sub
Private Sub TextBox13_Enter()

End Sub
Private Sub ComboBox1_Change()

End Sub

Private Sub textBox3_keyPress(ByVal keyAscii As MSForms.ReturnInteger)
    keyAscii = Asc(UCase(Chr(keyAscii)))
End Sub

Private Sub CommandButton2_Click()
Windows("AVP_Année en cours.xlsm").Activate
Sheets("Création de dossier").Select





Windows("fichier conservation dossier échantillons Année en cours.xlsm").Activate
Sheets("AVP+ Conservation sans anal").Select
Dim NE, de&
 NE = Array("AVP+ Conservation sans anal")
With Sheets(NE(CheckBox))
.Activate
Sheets("AVP+ Conservation sans anal").Select
de = .Cells(Rows.Count, "B").End(xlUp).Row + 1
    .Cells(de, "B") = TextBox1 & "   " & ComboBox7
    .Cells(de + 1, "B") = TextBox3
    .Cells(de + 2, "B") = TextBox4
    .Cells(de + 3, "B") = TextBox2 & IIf(TextBox12 < 10, " 0" & TextBox12, " " & TextBox12) & " " & TextBox13 & TextBox14
    .Cells(de, "F") = TextBox10 & " tubes"
    .Cells(de, "K") = TextBox2 & IIf(TextBox12 < 10, " 0" & TextBox12, " " & TextBox12) & " " & TextBox13 & TextBox14
    .Cells(de + 1, "K") = TextBox2 & IIf(TextBox12 < 10, " 0" & TextBox12, " " & TextBox12) & " " & TextBox13 & TextBox14
    .Cells(de + 2, "K") = TextBox2 & IIf(TextBox12 < 10, " 0" & TextBox12, " " & TextBox12) & " " & TextBox13 & TextBox14
    .Cells(de + 3, "K") = TextBox2 & IIf(TextBox12 < 10, " 0" & TextBox12, " " & TextBox12) & " " & TextBox13 & TextBox14
End With
xdlgn = Range("A65536").End(xlUp).Row
 
  Range("A5:K" & xdlgn).Select
  Range("K" & xdlgn).Activate
  Worksheets("AVP+ Conservation sans anal").Sort.SortFields.Clear
  Worksheets("AVP+ Conservation sans anal").Sort.SortFields.Add Key:=Range("K5:K" & xdlgn) _
        , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
  With ActiveWorkbook.Worksheets("AVP+ Conservation sans anal").Sort
      .SetRange Range("A5:K" & xdlgn)
      .Header = xlGuess
      .MatchCase = False
      .Orientation = xlTopToBottom
      .SortMethod = xlPinYin
      .Apply
  End With
  Range("A9").Select

'End If


 




'If CheckBox1.Value = True Then
Windows("AVP_Année en cours.xlsm").Activate

Sheets("AVP").Select
Dim NG, dg&
 NG = Array("AVP")
 
 
With Sheets(NG(CheckBox))
.Activate
Sheets("AVP").Select
dg = .Cells(Rows.Count, "C").End(xlUp).Row + 1
    .Cells(dg, "B") = TextBox1
    .Cells(dg, "C") = TextBox2 & IIf(TextBox12 < 10, " 0" & TextBox12, " " & TextBox12) & " " & TextBox13 & TextBox14
    .Cells(dg, "D") = TextBox3 & " " & TextBox4
    .Cells(dg, "F") = TextBox5 & "/" & TextBox15 & "/" & TextBox16
    .Cells(dg, "I") = IIf(CheckBox7, "U ", vbNullString) & IIf(CheckBox8, "S ", vbNullString) & IIf(CheckBox9, "NE ", vbNullString) & IIf(CheckBox10, "NP ", vbNullString)
    .Cells(dg, "H") = ComboBox5
    .Cells(dg, "E") = ComboBox7
    .Cells(dg, "U") = ComboBox10
    .Cells(dg, "BO") = ComboBox11
    .Cells(dg, "BF") = ComboBox1
    .Cells(dg, "BI") = ComboBox3
    .Cells(dg, "BJ") = ComboBox9
    .Cells(dg, "BK") = ComboBox4
    .Cells(dg, "BH") = ComboBox13
    .Cells(dg, "BG") = ComboBox12
    .Cells(dg, "BD") = TextBox18
    .Cells(dg, "BE") = TextBox19

    
If Cells(dg, "F") = "//" Then
Cells(dg, "F") = ""
End If

    
If Cells(dg, "F") <> "" Then
    datnais = Cells(dg, "F").Value
datdec = Now
 
jn = DatePart("d", datnais)
mn = DatePart("m", datnais)
an = DatePart("yyyy", datnais)
jd = DatePart("d", datdec)
md = DatePart("m", datdec)
ad = DatePart("yyyy", datdec)
 
'calcul nbre années
 
If md > mn Then qdm = "apres"
If md = mn Then qdm = "egal"
If md < mn Then qdm = "avt"
 
If jd > jn Then qdj = "apres"
If jd = jn Then qdj = "egal"
If jd < jn Then qdj = "avt"
 
If qdm = "apres" Then nbran = ad - an
If qdm = "apres" Then GoTo line1:
 
If qdm = "egal" And jd >= jn Then nbran = ad - an
If qdm = "egal" And jd >= jn Then GoTo line1:
 
nbran = ad - an - 1
GoTo line2:
 
'calcul nbre de jours si anniv ok
line1:
dattransf = DateSerial(ad, mn, jn)
nbrj = DateDiff("d", dattransf, datdec)
GoTo line3:
 
'calcul nbre de jours si anniv ko
line2:
dattransf1 = DateSerial(ad - 1, mn, jn)
datfinan = DateSerial(ad - 1, 12, 31)
jfinan = DateDiff("d", dattransf1, datfinan)
datdeban = DateSerial(ad, 1, 1)
jdeban = DateDiff("d", datdeban, datdec)
nbrj = jfinan + jdeban
 
line3:
        
    .Cells(dg, "G") = nbran
 
'Range("B1:BM1" & I).Sort Key1:=Range("C2"), Order1:=xlDescending
 
 End If
 
xdlgn = Range("A65536").End(xlUp).Row

  Range("B2:BM2" & xdlgn).Select
  Range("C" & xdlgn).Activate
  Worksheets("AVP").Sort.SortFields.Clear
  Worksheets("AVP").Sort.SortFields.Add Key:=Range("C2:C" & xdlgn) _
        , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
  With ActiveWorkbook.Worksheets("AVP").Sort
      .SetRange Range("B2:BM2" & xdlgn)
      .Header = xlGuess
      .MatchCase = False
      .Orientation = xlTopToBottom
      .SortMethod = xlPinYin
      .Apply
  End With
Range("A1").Select

 


    
End With


Windows("fichier conservation dossier échantillons Année en cours.xlsm").Activate
ActiveWorkbook.Save
Windows("AVP_Année en cours.xlsm").Activate
ActiveWorkbook.Save

Sheets("Création de dossier").Select



UserForm1.Hide
Unload UserForm1




End Sub

Private Sub Frame2_Click()

End Sub

Private Sub Label13_Click()

End Sub

Private Sub Label15_Click()

End Sub

Private Sub Label9_Click()

End Sub

Private Sub OptionButton1_Click()
Expert = 0
End Sub

Private Sub OptionButton2_Click()
Expert = 1
End Sub

Private Sub OptionButton3_Click()
Expert = 2
End Sub

Private Sub OptionButton4_Click()
Expert = 3
End Sub

Private Sub TextBox1_Change()

End Sub


Private Sub TextBox10_Change()

End Sub

Private Sub TextBox11_Change()

End Sub

Private Sub TextBox8_Change()

End Sub

Private Sub UserForm_Click()

End Sub

ne peut on pas lui donner l'ordre d'aller chercher le dossier voulu puis remplacer les valeurs modifiées?
 

aeryne

XLDnaute Junior
Re : remplir un userform à partir de ligne dans excel

j'ai trouvé ceci (et pourtant j'avais déjà cherché avant):
HTML:
http://www.excel-downloads.com/forum/160378-remplir-un-userform-partir-dune-feuille-excel.html

Je crois que je suis vraiment une buse car j'ai compris le code et pourtant je n'arrive pas à l'appliquer à mon fichier.
Y a t'il un autre lieu pour stocker mon fichier car il est vraiment trop volumineux pour l'envoyer ici même en l'épurant et sinon je dois tellement retiré d'info qu'il n'y a plus rien à voir.
 

aeryne

XLDnaute Junior
Re : remplir un userform à partir de ligne dans excel

Bon j'avance j'avance
j'ai reussi en partie mais il y a encore un souci:
j'arrive à aller chercher mes renseignement dans le tableau et à les mettre dans mon formulaire.
j'arrive à envoyer certaines des donnée modifier mais pas toute.j'ai l'impression qu'il ne veut pas prendre en compte les modification des combobox.
voici mon code actuel.
Merci pour ton aide
Code:
Private Sub ComboBox29_Change()

    Dim ligne As Integer
    Dim i As Integer
    
    i = 1
    ligne = -1
    With Sheets("AVP")
        Do While (.Range("D" & i) <> ComboBox29.Value And .Range("D" & i) <> Empty)
        i = i + 1
        Loop
        If (.Range("D" & i).Value = ComboBox29.Value) Then
            ligne = i
        End If
    End With
  
    If (ligne > 0) Then
        With Sheets("AVP")
                
            
        
        
            TextBox1.Value = .Range("B" & ligne).Value
            TextBox2.Value = .Range("C" & ligne).Value
            ComboBox29.Value = .Range("D" & ligne).Value
            ComboBox11.Value = .Range("E" & ligne).Value
            TextBox5.Value = .Range("F" & ligne).Value
            ComboBox5.Value = .Range("H" & ligne).Value
            ComboBox28.Value = .Range("I" & ligne).Value
            ComboBox7.Value = .Range("J" & ligne).Value
            ComboBox27.Value = .Range("K" & ligne).Value
            ComboBox10.Value = .Range("x" & ligne).Value
            
        End With
    End If
End Sub

Private Sub CommandButton22_Click()

Dim ligne As Integer
    Dim i As Integer
    
    i = 1
    ligne = -1
    With Sheets("AVP")
        Do While (.Range("D" & i) <> ComboBox29.Value And .Range("D" & i) <> Empty)
        i = i + 1
        Loop
        If (.Range("D" & i).Value = ComboBox29.Value) Then
            ligne = i
        End If
    End With
  
    If (ligne > 0) Then
        With Sheets("AVP")
 

    .Range("B" & ligne).Value = TextBox1.Value
    .Range("C" & ligne).Value = TextBox2.Value
    .Range("D" & ligne).Value = ComboBox29.Value
    .Range("E" & ligne).Value = ComboBox11.Value
    .Range("F" & ligne).Value = TextBox5.Value
    .Range("H" & ligne).Value = ComboBox5.Value
    .Range("I" & ligne).Value = ComboBox28.Value
    .Range("J" & ligne).Value = ComboBox7.Value
    .Range("K" & ligne).Value = ComboBox27.Value
    .Range("X" & ligne).Value = ComboBox10.Value
End With
    


 End If
 

Discussions similaires

Réponses
17
Affichages
249
Réponses
5
Affichages
365

Statistiques des forums

Discussions
311 720
Messages
2 081 915
Membres
101 837
dernier inscrit
Ugo