Redimensionner un tableau d'une taille variable

Bonjour,

Depuis le fichier "suivi par commanditaire, j'ouvre le fichier "évolution des études1.xlsm". Puis je lis dans chaque cellule de la colonne B du fichier "évolution des études1" de (18 à nb de lignes) un texte LULU. Puis à chaque détection du texte, je souhaite mettre la valeur de la colonne A associée dans un tableau nom(). La dimension du tableau dépend donc du nb de ligne avec "LULU". Comment dimensionner mon tableau au fur et à mesure de chaque ligne détectée avec le texte LULU.

merci beaucoup

jasserin

Option Explicit
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim Nb_Lignes As Integer
Dim Fichier  As String 'évolution des études
Dim Chemin As String '
Dim i As Integer
Dim x As Integer
Dim j As Integer
Dim k As Integer
Dim y As Integer
Dim LOREAL As String

Sub ouverture_fichier_évolutiondesétudes1()
Dim i As Integer
Fichier = "évolution des études.xlsm"
  Application.ScreenUpdating = False
  Chemin = "C:\users\utilisateur\Desktop" & Application.PathSeparator
  If Dir(Chemin & Fichier) = "" Then
    MsgBox "Fichier " & Fichier & " introuvable : Programme terminé"
    End
  End If
Workbooks.Open (Chemin & Fichier)
Call promoteur1

End Sub

Sub promoteur1()
Dim nom() As String
ReDim nom(j)

Set ws1 = Application.Workbooks("évolution des études1.xlsm").Sheets("2013")
Set ws2 = Application.Workbooks("Suivi par commanditaire 2013.xlsm").Sheets("Promoteur1")

Nb_Lignes = Range("A" & Cells.Rows.Count).End(xlUp).Row 'compte dernière ligne remplie de A

'tri par Lulu du classeur Evolution des études1 de la feuille 2013
j = 1
x = 0

For i = 18 To Nb_Lignes

If ws1.Range("B" & i).Value = "LULU" Then
   nom(j) = ws1.Range("A" & i).Value
  MsgBox nom(j)
   j = j + 1
    x = x + 1
    MsgBox x
End If

Next
 'For j = 1 To UBound(nom, 1)

  '    MsgBox "clients " & "=" & nom(j)

   'Next j

' creation des lignes

ws2.Range("A8").Select

'MsgBox nom(1)
'For j = 1 To x
'y = 8
'MsgBox nom(j)
'Range("A" & y).Value = nom(j)
'y = y + 1
'Next j

End Sub

Bonjour,

        For i = 1 To Nb_Lignes
            If Ws1.Range("B" & i).Value = "LULU" Then
                ReDim Preserve nom(j)
                nom(j) = Ws1.Range("A" & i).Value
                j = j + 1
            End If
        Next

A+

Bonjour

Bonjour frangy

De mémoire 2 solutions

Solution 1

j = 1
x = 0

For i = 18 To Nb_Lignes

If ws1.Range("B" & i).Value = "LULU" Then
 ReDim Preserve nom(j)
   nom(j) = ws1.Range("A" & i).Value
  MsgBox nom(j)
   j = j + 1
    x = x + 1
    MsgBox x
End If

Solution 2

j = 1
x = 0

  nb = Application.CountIf(ws1.Range("B18:B" & Nb_Lignes), "LULU")
  ReDim nom(nb)

For i = 18 To Nb_Lignes

If ws1.Range("B" & i).Value = "LULU" Then
   nom(j) = ws1.Range("A" & i).Value
  MsgBox nom(j)
   j = j + 1
    x = x + 1
    MsgBox x
End If

Rien de testé (pas de fichier)

super !

Merci beaucoup à vous deux.

Bonne soirée,

jasserin

Rechercher des sujets similaires à "redimensionner tableau taille variable"