Je n'arrive pas à trouver la ligne de code correspondant à mon UserForm1 permettant de rechercher les données et de les insérer dans mon UserForm2.
la ligne de code correspondant à mon UserForm1 permettant de rechercher les donnéesça ne sera surement pas qu'une seule ligne de code....
les insérer dans mon UserForm2C'est de la manipulation basique de userform.
Userform2.TextBox1.value = "Mon blabla"
'Tu déclares en Public les variables : vcLig et vcCol Public vcLig As Integer Public vcCol As Integer Function cherchC(nomF As String, valCherch As String) As Boolean 'fonction de recherche... '********************************************************** ' recherche la valeur 'valCherch' et nous indique le ' N° de ligne et de Colonne où elle se trouve VcLig / VcCol '********************************************************** Dim vc As Variant Sheets(nomF).Activate Sheets(nomF).Cells(1, 1).Activate Set vc = Cells.Find(what:=valCherch, lookAt:=xlWhole, After:=ActiveCell, SearchOrder:=xlByColumns, SearchDirection:=xlNext, LookIn:=xlValues, MatchCase:=False, SearchFormat:=False) If Not vc Is Nothing Then vcCol = vc.Column vcLig = vc.Row cherchC = True End If End Function '---------------------------------------- 'Exemple d'utilisation '---------------------------------------- Sub Test() Dim recherche As Boolean recherche = cherchC("Feuil1", "toto") If recherche = True Then MsgBox ("Valeur trouvée en : ligne: " & vcLig & " Colonne: " & vcCol) Else MsgBox ("Aucun résultat trouvé") End If End Sub
Private Sub CommandButton1_Click() Dim x As Integer x = 0 Do If TextBox1.Value = Sheets("Véhicules").Range("A2").Offset(0, x) Then Else Sheets("Véhicules").Range("A2").Offset(x, 0).Select x = x + 1 End If Loop Until a = Sheets("Véhicules").Range("A2").Offset(0, x) ModificationVéhicule1.Show ModificationVéhicule1.TextBox1.Value = Sheets("Véhicules").Range("A2") ModificationVéhicule1.TextBox2.Value = Sheets("Véhicules").Range("B2") ModificationVéhicule1.TextBox3.Value = Sheets("Véhicules").Range("C2") ModificationVéhicule1.TextBox4.Value = Sheets("Véhicules").Range("D2") ModificationVéhicule1.TextBox5.Value = Sheets("Véhicules").Range("E2") ModificationVéhicule1.TextBox6.Value = Sheets("Véhicules").Range("F2") ModificationVéhicule1.TextBox7.Value = Sheets("Véhicules").Range("G2") ModificationVéhicule1.TextBox8.Value = Sheets("Véhicules").Range("H2") ModificationVéhicule1.TextBox9.Value = Sheets("Véhicules").Range("I2") ModificationVéhicule1.TextBox10.Value = Sheets("Véhicules").Range("J2") ModificationVéhicule1.TextBox11.Value = Sheets("Véhicules").Range("K2") ModificationVéhicule1.TextBox12.Value = Sheets("Véhicules").Range("L2") ModificationVéhicule1.TextBox13.Value = Sheets("Véhicules").Range("M2") Unload Me End Sub
Private Sub CommandButton1_Click() Dim recherche As Boolean recherche = cherchC("Feuil4", TextBox1.Value) If recherche = True Then MsgBox ("Valeur trouvée en : ligne: " & vcLig & " Colonne: " & vcCol) Else MsgBox ("Aucun résultat trouvé") End If End Sub
Private Sub CommandButton1_Click() Dim recherche As Boolean recherche = cherchC("Véhicules", TextBox1.Value) If recherche = True Then ' MsgBox ("Valeur trouvée en : ligne: " & vcLig & " Colonne: " & vcCol) 'Colonne A ligne : vcLig ModificationVéhicule1.TextBox1.Value = Sheets("Véhicules").cells(vcLig,1) 'Colonne B ligne : vcLig ModificationVéhicule1.TextBox2.Value = Sheets("Véhicules").cells(vcLig,2) ' Etc..... Else MsgBox ("Aucun résultat trouvé") End If End Sub
Do If TextBox1.Value <> Sheets("Véhicules").Range("A2").Offset(0, x) Then Sheets("Véhicules").Range("A2").Offset(x, 0).Select x = x + 1 End If Loop Until a = Sheets("Véhicules").Range("A2").Offset(0, x)
Loop Until a = Sheets("Véhicules").Range("A2").Offset(x,0)
ModificationVéhicule1.TextBox1.Value = Sheets("Véhicules").Range("A2")
ModificationVéhicule1.TextBox1.Value = Sheets("Véhicules").Range("A2").Offset(x,0)
Public vcLig As Integer
Public vcCol As Integer
Private Sub CommandButton1_Click()
Dim recherche As Boolean
recherche = cherchC("Véhicules", TextBox1.Value)
If recherche = True Then
MsgBox ("Valeur trouvée en : ligne: " & vcLig & " Colonne: " & vcCol)
ModificationVéhicule1.Show
ModificationVéhicule1.TextBox1.Value = Sheets("Véhicules").Cells(vcCol, A)
ModificationVéhicule1.TextBox2.Value = Sheets("Véhicules").Cells(vcCol, B)
ModificationVéhicule1.TextBox3.Value = Sheets("Véhicules").Cells(vcCol, C)
ModificationVéhicule1.ComboBox1.Value = Sheets("Véhicules").Cells(vcCol, D)
ModificationVéhicule1.TextBox5.Value = Sheets("Véhicules").Cells(vcCol, E)
ModificationVéhicule1.TextBox4.Value = Sheets("Véhicules").Cells(vcCol, F)
ModificationVéhicule1.ComboBox2.Value = Sheets("Véhicules").Cells(vcCol, G)
ModificationVéhicule1.TextBox6.Value = Sheets("Véhicules").Cells(vcCol, H)
ModificationVéhicule1.TextBox8.Value = Sheets("Véhicules").Cells(vcCol, I)
ModificationVéhicule1.TextBox9.Value = Sheets("Véhicules").Cells(vcCol, J)
ModificationVéhicule1.TextBox10.Value = Sheets("Véhicules").Cells(vcCol, K)
ModificationVéhicule1.TextBox11.Value = Sheets("Véhicules").Cells(vcCol, L)
ModificationVéhicule1.TextBox12.Value = Sheets("Véhicules").Cells(vcCol, M)
Else
MsgBox ("Aucun résultat trouvé")
End If
End Sub
' ModificationVéhicule1.TextBox1.Value = Sheets("Véhicules").Cells(vcCol, A) ' devient : ModificationVéhicule1.TextBox1.Value = Sheets("Véhicules").Cells(vcLigl, 1) ' etc...
Private Sub CommandButton1_Click()
Dim recherche As Boolean
recherche = cherchC("Véhicules", TextBox1.Value)
If recherche = True Then
MsgBox ("Valeur trouvée en : ligne: " & vcLig & " Colonne: " & vcCol)
ModificationVéhicule1.Show
ModificationVéhicule1.TextBox1.Value = Sheets("Véhicules").Cells(cvLig, 1)
ModificationVéhicule1.TextBox2.Value = Sheets("Véhicules").Cells(vcLig, 2)
ModificationVéhicule1.TextBox3.Value = Sheets("Véhicules").Cells(vcLig, 3)
ModificationVéhicule1.ComboBox1.Value = Sheets("Véhicules").Cells(vcLig, 4)
ModificationVéhicule1.TextBox5.Value = Sheets("Véhicules").Cells(vcLig, 5)
ModificationVéhicule1.TextBox4.Value = Sheets("Véhicules").Cells(vcLig, 6)
ModificationVéhicule1.ComboBox2.Value = Sheets("Véhicules").Cells(vcLig, 7)
ModificationVéhicule1.TextBox6.Value = Sheets("Véhicules").Cells(vcLig, 8)
ModificationVéhicule1.TextBox8.Value = Sheets("Véhicules").Cells(vcLig, 9)
ModificationVéhicule1.TextBox9.Value = Sheets("Véhicules").Cells(vcLig, 10)
ModificationVéhicule1.TextBox10.Value = Sheets("Véhicules").Cells(vcLig, 11)
ModificationVéhicule1.TextBox11.Value = Sheets("Véhicules").Cells(vcLig, 12)
ModificationVéhicule1.TextBox12.Value = Sheets("Véhicules").Cells(vcLig, 13)
Else
MsgBox ("Aucun résultat trouvé")
End If
End Sub
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionMessage : erreur de compilation Sub ou Function non définiEt tu as bien mis dans un Module la fonction cherchC ?
Surligné : "cherchC
Private Sub CommandButton1_Click()
Dim recherche As Boolean
recherche = cherchC("Véhicules", TextBox1.Value)
If recherche = True Then
MsgBox ("Valeur trouvée en : ligne: " & vcLig & " Colonne: " & vcCol)
ModificationVéhicule1.Show
ModificationVéhicule1.TextBox1.Value = Sheets("Véhicules").Cells(cvLig, 1)
ModificationVéhicule1.TextBox2.Value = Sheets("Véhicules").Cells(vcLig, 2)
ModificationVéhicule1.TextBox3.Value = Sheets("Véhicules").Cells(vcLig, 3)
ModificationVéhicule1.ComboBox1.Value = Sheets("Véhicules").Cells(vcLig, 4)
ModificationVéhicule1.TextBox5.Value = Sheets("Véhicules").Cells(vcLig, 5)
ModificationVéhicule1.TextBox4.Value = Sheets("Véhicules").Cells(vcLig, 6)
ModificationVéhicule1.ComboBox2.Value = Sheets("Véhicules").Cells(vcLig, 7)
ModificationVéhicule1.TextBox6.Value = Sheets("Véhicules").Cells(vcLig, 8)
ModificationVéhicule1.TextBox8.Value = Sheets("Véhicules").Cells(vcLig, 9)
ModificationVéhicule1.TextBox9.Value = Sheets("Véhicules").Cells(vcLig, 10)
ModificationVéhicule1.TextBox10.Value = Sheets("Véhicules").Cells(vcLig, 11)
ModificationVéhicule1.TextBox11.Value = Sheets("Véhicules").Cells(vcLig, 12)
ModificationVéhicule1.TextBox12.Value = Sheets("Véhicules").Cells(vcLig, 13)
Else
MsgBox ("Aucun résultat trouvé")
End If
End Sub
Public vcLig As Integer
Public vcCol As Integer
Function cherchC(Véhicules As String, valCherch As String) As Boolean
Dim vc As Variant
Sheets(Véhicules).Activate
Sheets(Véhicules).Cells(1, 1).Activate
Set vc = Cells.Find(what:=valCherch, lookAt:=xlWhole, After:=ActiveCell, SearchOrder:=xlByColumns, SearchDirection:=xlNext, LookIn:=xlValues, MatchCase:=False, SearchFormat:=False)
If Not vc Is Nothing Then
vcCol = vc.Column
vcLig = vc.Row
cherchC = True
End If
End Function
'Tu déclares en Public les variables : vcLig et vcCol Public vcLig As Integer Public vcCol As Integer Function cherchC(nomF As String, valCherch As String) As Boolean 'fonction de recherche... '********************************************************** ' recherche la valeur 'valCherch' et nous indique le ' N° de ligne et de Colonne où elle se trouve VcLig / VcCol '********************************************************** Dim vc As Variant Sheets(nomF).Activate Sheets(nomF).Cells(1, 1).Activate Set vc = Cells.Find(what:=valCherch, lookAt:=xlWhole, After:=ActiveCell, SearchOrder:=xlByColumns, SearchDirection:=xlNext, LookIn:=xlValues, MatchCase:=False, SearchFormat:=False) If Not vc Is Nothing Then vcCol = vc.Column vcLig = vc.Row cherchC = True End If End Function
ModificationVéhicule1.TextBox1.Value = Sheets("Véhicules").Cells(cvLig, 1)
ModificationVéhicule1.TextBox1.Value = Sheets("Véhicules").Cells(vcLig, 1)
Userform1.textBox1.value = valeur de ma cellule
Modifié par SandraMt le 5/06/2014 à 10:27
je ne connaissais rien au langage VBA avant ce projet donc je ne suis pas très douée ... Donc même une méthode basique me paraît compliquée ..
Quelles sont les règles pour la méthode Find ?
Merci de votre réponse