0% ont trouvé ce document utile (0 vote)
21 vues4 pages

Code VBA pour gérer UserForm Excel

Le document fournit un code VBA pour un UserForm Excel permettant d'ajouter, de supprimer, de modifier et de rechercher des données. Il inclut des exemples de code pour chaque fonctionnalité, avec des champs spécifiques pour le nom, le prénom et le téléphone. Une méthode de recherche est également fournie pour trouver un nom dans une feuille de calcul et afficher les informations correspondantes.

Transféré par

wifinayrehetra
Copyright
© All Rights Reserved
Nous prenons très au sérieux les droits relatifs au contenu. Si vous pensez qu’il s’agit de votre contenu, signalez une atteinte au droit d’auteur ici.
Formats disponibles
Téléchargez aux formats PDF, TXT ou lisez en ligne sur Scribd
0% ont trouvé ce document utile (0 vote)
21 vues4 pages

Code VBA pour gérer UserForm Excel

Le document fournit un code VBA pour un UserForm Excel permettant d'ajouter, de supprimer, de modifier et de rechercher des données. Il inclut des exemples de code pour chaque fonctionnalité, avec des champs spécifiques pour le nom, le prénom et le téléphone. Une méthode de recherche est également fournie pour trouver un nom dans une feuille de calcul et afficher les informations correspondantes.

Transféré par

wifinayrehetra
Copyright
© All Rights Reserved
Nous prenons très au sérieux les droits relatifs au contenu. Si vous pensez qu’il s’agit de votre contenu, signalez une atteinte au droit d’auteur ici.
Formats disponibles
Téléchargez aux formats PDF, TXT ou lisez en ligne sur Scribd

I​ reto avy ny *code VBA fototra* ho an'ny *Excel UserForm*

ahafahana manao :

- *Ajouter* (manampy donnée)


- *Supprimer* (mamafa donnée)
- *Modifier* (manova donnée)
- *Rechercher* (mitady donnée)

Atao hoe manana *UserForm* ianao (ex: `UserForm1`) misy


champ toy izao :
- `txtNom` (anarana)
- `txtPrenom` (fanampiny)
- `txtTel` (finday)
- `ListBox1` (fampisehoana liste)

*1. Ajouter :*
```vba
Private Sub btnAjouter_Click()
Dim ligne As Long
ligne = Sheets("Feuil1").Cells([Link], 1).End(xlUp).Row + 1
With Sheets("Feuil1")
.Cells(ligne, 1).Value = [Link]
.Cells(ligne, 2).Value = [Link]
.Cells(ligne, 3).Value = [Link]
End With
Call ActualiserListe
End Sub
```

*2. Supprimer :*
```vba
Private Sub btnSupprimer_Click()
If [Link] = -1 Then Exit Sub
Dim ligne As Long
ligne = [Link] + 2
Sheets("Feuil1").Rows(ligne).Delete
Call ActualiserListe
End Sub
```

*3. Modifier :*
```vba
Private Sub btnModifier_Click()
If [Link] = -1 Then Exit Sub
Dim ligne As Long
ligne = [Link] + 2
With Sheets("Feuil1")
.Cells(ligne, 1).Value = [Link]
.Cells(ligne, 2).Value = [Link]
.Cells(ligne, 3).Value = [Link]

Ity ambany ity ny *bouton "Recherche"* feno ho an’ny *UserForm*


amin’ny Excel VBA, izay mitady anarana iray ao amin'ny *Feuil1*,
puis mampiseho ny mombamomba azy amin'ny champ hafa:
*Code ho an'ny bouton “Rechercher” :*

```vba
Private Sub btnRecherche_Click()
Dim i As Long, trouve As Boolean
Dim nomRecherche As String
nomRecherche = [Link]

For i = 2 To Sheets("Feuil1").Cells([Link], 1).End(xlUp).Row


If Sheets("Feuil1").Cells(i, 1).Value = nomRecherche Then
[Link] = Sheets("Feuil1").Cells(i, 2).Value
[Link] = Sheets("Feuil1").Cells(i, 3).Value
trouve = True
Exit For
End If
Next i

If Not trouve Then


MsgBox "Tsy hita ilay anarana", vbExclamation
[Link] = ""
[Link] = ""
End If
End Sub
```

*Fepetra:*
- `txtNom` = ilay champ fidirana anarana tadiavina.
- `txtPrenom` sy `txtTel` = ilay hisehoan’ny valiny.
- Azonao ovaina araka ny anaran’ny textbox-nao.

Lazao raha mila ho *recherche partielle* (oh: mitady anarana


manomboka amin’ny litera iray), dia omeko code hafa.

Vous aimerez peut-être aussi