0

I am trying to make an application which lets you add new Suppliers (Fournisseurs in french) to a Worksheets("Fournisseurs") when I click on the button ''ADD Suppliers'' which is in Worksheets("Accueil")

I would like to add a new suppliers without opening Worksheets("Fournisseurs").Select and staying just in Worksheets("Accueil")

Any idea?

Sub NouveauFournisseur() 'OK
Dim i As Integer

Worksheets("Fournisseurs").Select 'sélection de la feuille
creation_fournisseur.Show 'affichage de l'userform

If OK Then
    i = 0 'boucle pr trouver la ligne vide où copier les données dans le formulaire
    Do
        i = i + 1
    Loop Until Cells(i, 1) = "" 'jusqu'à ce qu'une ligne soit vide
    Cells(i, 1) = creation_fournisseur.zt_nom
    Cells(i, 2) = creation_fournisseur.zt_adresse
    Cells(i, 3) = Val(creation_fournisseur.zt_tel)
    Cells(i, 4) = Val(creation_fournisseur.zt_fax)
End If

Unload creation_fournisseur 'fermer l'userform
Worksheets("Accueil").Select 'retour page d'acceuil après avoir rentré le fournisseur

End Sub

Community
  • 1
  • 1
zakaria
  • 13
  • 4

2 Answers2

0

Something like this

Sub NouveauFournisseur() 'OK

    Dim i As Integer, shtF As WorkSheet

    Set shtF = ThisWorkbook.Worksheets("Fournisseurs")

    creation_fournisseur.Show 'affichage de l'userform

    If OK Then
        i = 0 'boucle pr trouver la ligne vide où copier les données dans le formulaire
        Do
            i = i + 1
        Loop Until shtF.Cells(i, 1) = "" 'jusqu'à ce qu'une ligne soit vide
        shtF.Cells(i, 1) = creation_fournisseur.zt_nom
        shtF.Cells(i, 2) = creation_fournisseur.zt_adresse
        shtF.Cells(i, 3) = Val(creation_fournisseur.zt_tel)
        shtF.Cells(i, 4) = Val(creation_fournisseur.zt_fax)
    End If

    Unload creation_fournisseur 'fermer l'userform

End Sub
Tim Williams
  • 154,628
  • 8
  • 97
  • 125
0

You could also add: Sub NouveauFournisseur() 'OK

Dim i As Integer, shtF As WorkSheet

Set shtF = ThisWorkbook.Worksheets("Fournisseurs")

Worksheets("Accueil").activate
Worksheets("Accueil").Select
call moduleX.creation_fournisseur.Show
call formY.creation_fournisseur.Show

'creation_fournisseur.Show 'affichage de l'userform

If OK Then
    i = 0 'boucle pr trouver la ligne vide où copier les données dans le formulaire
    Do
        i = i + 1
    Loop Until shtF.Cells(i, 1) = "" 'jusqu'à ce qu'une ligne soit vide
    shtF.Cells(i, 1) = creation_fournisseur.zt_nom
    shtF.Cells(i, 2) = creation_fournisseur.zt_adresse
    shtF.Cells(i, 3) = Val(creation_fournisseur.zt_tel)
    shtF.Cells(i, 4) = Val(creation_fournisseur.zt_fax)
End If

Worksheets("Accueil").activate
Worksheets("Accueil").Select

Unload creation_fournisseur 'fermer l'userform

Worksheets("Accueil").activate
Worksheets("Accueil").Select

End Sub

Where ModuleX or FormY contain the sub for creation_fournisseur respectively.

So that you just directly call the form without opening another sheet, like they suggested here: Call a Subroutine from a different Module in VBA

(A little bit of overkill with all the activations and selecting, but you get the idea)

Community
  • 1
  • 1
a.t.
  • 2,002
  • 3
  • 26
  • 66