Show the same userform N times with a different title.

VBAKIDS Posted messages 5 Status Member -  
cs_Le Pivert Posted messages 8437 Status Contributor -
Bonjour, je suis novice en VBA et vous demande d'être indulgent.

J'ai créé un userform avec des labels, des textbox, etc. Je souhaiterais pouvoir afficher plusieurs fois en fonction de la valeur d'une cellule, ce userform avec une légère différence qui est le nom de mon labelfield. Voici le code que j'ai mis pour changer le nom de ce dernier :

For i = 1 To Sheets("Accueil").Range("E12").Value
UserForm1.Label1.Caption = Cells(i, 27).Value
Next i

i peut aller jusqu'à 100 par défaut. En conséquence, je souhaiterais pouvoir faire apparaître 100 fois mon userform avec tout le temps un nom différent (exemple : pour i=1 mon premier Userform est "Paroi " ... jusqu'à i=x "Paroi x".
Je n'ai vraiment aucune piste à part créer 100 fois le même userform et changer les valeurs du code à l'intérieur de chaque userform, autant dire que dans 2 ans j'aurais peut-être réussi à finir ^^!
Je compte créer à l'intérieur du userform modèle un code comme celui-ci :

Cells(9 + 6 * (i - 1), 2).Select
With Selection.Font
.ThemeColor = xlThemeColorLight1
.TintAndShade = 0
End With
Cells(9 + 6 * (i - 1), 2).Select
ActiveCell.FormulaR1C1 = "Matériau Paroi 1"

Cells(9 + 6 * (i - 1), 3).Select
ActiveCell.FormulaR1C1 = "Nom"

Cells(9 + 6 * (i - 1), 4).Select
ActiveCell.FormulaR1C1 = "Epaisseur (m)"
Next i
Cells(9 + 6 * (i - 1), 5).Select
ActiveCell.FormulaR1C1 = "Conductivité thermique (W/m.K)"

Cells(9 + 6 * (i - 1), 6).Select
ActiveCell.FormulaR1C1 = "Résistance thermique R "

Cells(10 + 6 * (i - 1), 6).Select
ActiveCell.FormulaR1C1 = "1"

Cells(11 + 6 * (i - 1), 6).Select
ActiveCell.FormulaR1C1 = "2"

Cells(12 + 6 * (i - 1), 6).Select
ActiveCell.FormulaR1C1 = "3"

Cells(13 + 6 * (i - 1), 6).Select
ActiveCell.FormulaR1C1 = "4"

' Cells(9+6*(i-1),2:9+6*(i-1),6).Select (Au passage, comment traduire avec cells Range("A6:J9") par exemple ?
Any suggestion ?

Merci d'avance à ceux qui pourront me répondre.

Cordialement

2 answers

  1. cs_Le Pivert Posted messages 8437 Status Contributor 730
     
    Hello,

    Use a ComboBox in which you would list your 100 names that will be listed in a column beforehand. Then you just need to select the one you want from your ComboBox by assigning the selected name to your UserForm.

    See this

    https://silkyroad.developpez.com/VBA/ControlesUserForm/#LII-F

    --
    @+ The Woodpecker
    0
    1. VBAKIDS Posted messages 5 Status Member
       
      Thank you for the time taken, but this is not at all what I am trying to achieve. The "template" userform needs to be able to repeat as many times as the value indicated in a cell. The only thing that changes in the userform between the first time I fill it out and the Nth time is a labelfield. For the name change, I think I need to correct my for loop, but as long as I am blocked from consecutively opening my window, I am stuck...

      I want Pane 1 to appear, once completed I automatically open Pane 2, once completed I open (automatically) Pane 3, etc...
      0
    2. VBAKIDS Posted messages 5 Status Member
       
      Sorry, but that's not what I'm looking for.. :/
      0
  2. VBAKIDS Posted messages 5 Status Member
     
    Pour le moment, voici où en est mon code :

    Sub Rectangle1_Click()

    Dim Form As New UserForm1

    For i = 1 To Sheets("Accueil").Range("E12").Value
    Form.Label1.Caption = Cells(i, 27).Value

    If Sheets("Accueil").Range("E12").Value <> "" Then
    Form.Show
    End If

    Next i

    'UserForm1.Show

    End Sub

    J'arrive à faire apparaître mon UserForm1 à l'infini (et au-delà), mais je n'arrive pas à le faire apparaître autant de fois que la valeur de mon i... Et mon code pour modifier le label ne semble plus fonctionner avec Form... Une idée ?
    0
    1. VBAKIDS Posted messages 5 Status Member
       
      Wow! I didn't expect something so complete! I started on something else but I'll keep it in mind if my code doesn't match what I'm looking for. Thank you very much @cs_Le Pivert.
      0
    2. cs_Le Pivert Posted messages 8437 Status Contributor 730
       
      As I see your interest, I had fun customizing the code, you just need to adapt it:

      https://www.cjoint.com/c/HLEkjiviURQ

      @+ Le Pivert
      0