Utilisation d'une boucle pour afficher des élément d'un tableau

Fermé
AnonymousX_7880 Messages postés 3 Date d'inscription lundi 5 août 2019 Statut Membre Dernière intervention 6 août 2019 - 5 août 2019 à 15:00
AnonymousX_7880 Messages postés 3 Date d'inscription lundi 5 août 2019 Statut Membre Dernière intervention 6 août 2019 - 6 août 2019 à 09:20
Bonjour à tous je suis nouveau sur vba, et je voulais savoir s’il y’a u’e manière plus facile (avec une boucle évidemment) d’afficher le contenu d’un tableau,
Voici mon code
If média. Value= “AI” Then
Me. TextBox= Sheets(“feuill). Range(” AJ3") & vbcrlf & Sheets(“feuill). Range(” AJ4") Sheets(“feuill). Range(” AJ5")
Ça devient lourd si je dois faire la même opération jusqu’à 100 fois
Merci d’avance pour votre aide????

2 réponses

yg_be Messages postés 22724 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 25 avril 2024 1 476
5 août 2019 à 17:21
bonjour, peut-être ainsi:
Dim cl As Range, texte As String
texte = ""
For Each cl In Sheets("feuill").Range("AJ3:AJ102")
    texte = texte + vbcrlf + CStr(cl)
Next cl 
Me.TextBox=texte
0
AnonymousX_7880 Messages postés 3 Date d'inscription lundi 5 août 2019 Statut Membre Dernière intervention 6 août 2019
6 août 2019 à 09:19
Merci beaucoup, je m'en vais tout de suite essayer le code
0
Patrice33740 Messages postés 8556 Date d'inscription dimanche 13 juin 2010 Statut Membre Dernière intervention 2 mars 2023 1 776
Modifié le 5 août 2019 à 17:23
Bonjour,

Par exemple:
Option Explicit
Sub Test()
Dim rng As Range
Dim tbl As Variant
Dim txt As String
  If média.Value = “AI” Then
    Set rng = Worksheets("Feuil1").Range("AJ3:AJ52")
    tbl = Application.Transpose(rng.Value)
    txt = Join(tbl, vbCrLf)
    Me.Textbox = txt
  End If
End Sub

Voir cet excellent cours VBA gratuit pour débutants :
ftp://ftp-developpez.com/bidou/Cours/VBA/formationVBA.pdf

0
AnonymousX_7880 Messages postés 3 Date d'inscription lundi 5 août 2019 Statut Membre Dernière intervention 6 août 2019
6 août 2019 à 09:20
Merci bcp pour le liens et le code, merci
0