Sub Selectionner9(NameCol1$, NameCol2$, NameCol3$, NameCol4$, NameCol5$)
Dim col, deb As Range, i%, lig&, derlig&
col = Array(NameCol1, NameCol2, NameCol3, NameCol4, NameCol5)
Set deb = Range(col(0))(1) '1ère cellule
On Error Resume Next 'si une plage est vide
With deb.Resize(Rows.Count - deb.Row + 1, Columns.Count - deb.Column + 1)
For i = 0 To UBound(col)
lig = 0
lig = Intersect(.Cells, Range(col(i))) _
.Find("*", , xlValues, , xlByRows, xlPrevious).Row
'.Find("*", , xlFormulas, , xlByRows, xlPrevious).Row 'autre possibilité
If lig > derlig Then derlig = lig
Next
End With
Range(deb, Cells(derlig, Range(col(i - 1)).Column)).Select
End Sub
Sub Selectionner9(NameCol1$, NameCol2$, NameCol3$, NameCol4$, NameCol5$)
Dim col, deb As Range, i%, lig&, derlig&
col = Array(NameCol1, NameCol2, NameCol3, NameCol4, NameCol5)
Set deb = Range(col(0))(1) '1ère cellule
On Error Resume Next 'si une plage est vide
For i = 0 To UBound(col)
lig = 0
lig = Range(col(i)).Find("*", , xlValues, , xlByRows, xlPrevious).Row
'lig = Range(col(i)).Find("*", , xlFormulas, , xlByRows, xlPrevious).Row 'autre
If lig > derlig Then derlig = lig
Next
If derlig < deb.Row Then MsgBox "Aucune sélection possible...": Exit Sub
Range(deb, Cells(derlig, Range(col(i - 1)).Column)).Select
End Sub
Sub SelectColonnes(NameCol1$, NameCol2$, Optional NameCol3$, Optional NameCol4$, Optional NameCol5$)
'Sélectionne un ensemble (ici) de 5 colonnes
'Attention ! Le début de toutes les colonnes doit se trouver sur la même ligne
'- NameCol1 à NameCol5 : nom des 5 colonnes nommées
'job75
Dim col, deb As Range, i%, lig&, derlig&
col = Array(NameCol1, NameCol2, NameCol3, NameCol4, NameCol5)
Set deb = Range(col(0))(1) '1ère cellule
On Error Resume Next 'si une plage est vide
For i = 0 To UBound(col)
lig = 0
lig = Range(col(i)).Find("*", , xlValues, , xlByRows, xlPrevious).Row
'lig = Range(col(i)).Find("*", , xlFormulas, , xlByRows, xlPrevious).Row 'autre possibilité
If lig > derlig Then derlig = lig
Next
If derlig < deb.Row Then Exit Sub
Range(deb, Cells(derlig, Range(col(i - 1)).Column)).Select
End Sub
Call SelectColonnes("Import_Colonne1", "Import_Colonne2")
Sub SelectColonnes(NameCol1$, NameCol2$)
'Sélectionne un ensemble (ici) de 2 colonnes
'Attention ! Le début de toutes les colonnes doit se trouver sur la même ligne
'- NameCol1 à NameCol2 : nom des 2 colonnes nommées
'job75
Dim col, deb As Range, i%, lig&, derlig&
col = Array(NameCol1, NameCol2)
Set deb = Range(col(0))(1) '1ère cellule
On Error Resume Next 'si une plage est vide
For i = 0 To UBound(col)
lig = 0
lig = Range(col(i)).Find("*", , xlValues, , xlByRows, xlPrevious).Row
'lig = Range(col(i)).Find("*", , xlFormulas, , xlByRows, xlPrevious).Row 'autre possibilité
If lig > derlig Then derlig = lig
Next
If derlig < deb.Row Then Exit Sub
Range(deb, Cells(derlig, Range(col(i - 1)).Column)).Select
End Sub
Sub SelectColonnes(NameCol1, NameCol2, Optional NameCol3 = 0, Optional NameCol4 = 0, Optional NameCol5 = 0)
'-----
i = Application.Match("zzz", col) 'détermine le dernier paramètre utile
Range(deb, Cells(derlig, Range(col(i - 1)).Column)).Select
End Sub
Sub SelectColonnes(NameCol1$, NameCol2$, Optional NameCol3$, Optional NameCol4$, Optional NameCol5$)
Dim col, deb As Range, i%, lig&, derlig&
col = Array(NameCol1, NameCol2, NameCol3, NameCol4, NameCol5)
Set deb = Range(col(0))(1) '1ère cellule
On Error Resume Next 'si une plage est vide
For i = 0 To UBound(col)
If col(i) = "" Then Exit For '1er paramètre non défini
lig = 0
lig = Range(col(i)).Find("*", , xlValues, , xlByRows, xlPrevious).Row
'lig = Range(col(i)).Find("*", , xlFormulas, , xlByRows, xlPrevious).Row 'autre possibilité
If lig > derlig Then derlig = lig
Next
If derlig < deb.Row Then Exit Sub
Range(deb, Cells(derlig, Range(col(i - 1)).Column)).Select
End Sub
Call SelectColonnes("Colonne1", "Colonne2")
Call SelectColonnes("Colonne2", "Colonne4")
Call SelectColonnes("Colonne1", "Colonne36")
Sub SelectColonnes(NameCol1$, NameCol2$)
'Sélectionne un ensemble de colonnes (plages verticales de cellules contiguës), avec les colonnes intermédiaires
'(s'il y en a) les séparant dont les extrêmes sont les plages nommées "NameCol1" & "NameCol2"
'Attention ! Le début de toutes les colonnes doit se trouver sur la même ligne
'- NameCol1 à NameCol2 : nom de 2 colonnes nommées
'job75
Dim col, deb As Range, i%, lig&, derlig&
col = Array(NameCol1, NameCol2)
Set deb = Range(col(0))(1) '1ère cellule
On Error Resume Next 'si une plage est vide
For i = 0 To UBound(col)
lig = 0
lig = Range(col(i)).Find("*", , xlValues, , xlByRows, xlPrevious).Row
'lig = Range(col(i)).Find("*", , xlFormulas, , xlByRows, xlPrevious).Row 'autre possibilité
If lig > derlig Then derlig = lig
Next
If derlig < deb.Row Then Exit Sub
Range(deb, Cells(derlig, Range(col(i - 1)).Column)).Select
End Sub
Sub SelectColonnes(Nomcol$)
Dim mincol%, nom As Name, deb As Range, maxcol%, lig&, derlig&
mincol = Columns.Count
On Error Resume Next 'si une plage est vide
For Each nom In ThisWorkbook.Names
If nom.Name Like Nomcol & "*" Then
With Range(nom.Name)
If .Column < mincol Then mincol = .Column: Set deb = .Cells(1)
If .Column > maxcol Then maxcol = .Column
lig = 0
lig = .Find("*", , xlValues, , xlByRows, xlPrevious).Row
'lig = .Find("*", , xlFormulas, , xlByRows, xlPrevious).Row 'autre possibilité
If lig > derlig Then derlig = lig
End With
End If
Next
If derlig < deb.Row Then Exit Sub
Range(deb, Cells(derlig, maxcol)).Select
End Sub
Call SelectColonnes("Colonne")
Sub SelectColonnes(Nomcol$)
Dim mincol%, minlig&, nom As Name, maxcol%, lig&, maxlig&
mincol = Columns.Count
minlig = Rows.Count
On Error Resume Next 'si une plage est vide
For Each nom In ThisWorkbook.Names
If nom.Name Like Nomcol & "*" Then
With Range(nom.Name)
If .Column < mincol Then mincol = .Column
If .Column > maxcol Then maxcol = .Column
If .Row < minlig Then minlig = .Row
lig = 0
lig = .Find("*", , xlValues, , xlByRows, xlPrevious).Row
'lig = .Find("*", , xlFormulas, , xlByRows, xlPrevious).Row 'autre possibilité
If lig > maxlig Then maxlig = lig
End With
End If
Next
Range(Cells(minlig, mincol), Cells(maxlig, maxcol)).Select
'If maxlig = 0 Then MsgBox "Aucune sélection possible..." 'facultatif
End Sub
ta dernière macro, presqiue parfaite
Sub SelectColonnes(Nomcol$, deb&, fin&)
Dim mincol%, minlig&, nom As Name, n&, maxcol%, lig&, maxlig&
mincol = Columns.Count
minlig = Rows.Count
On Error Resume Next 'si une plage est vide
For Each nom In ThisWorkbook.Names
n = Val(Replace(nom.Name, Nomcol, ""))
If nom.Name Like Nomcol & "*" And n >= deb And n <= fin Then
With Range(nom.Name)
If .Column < mincol Then mincol = .Column
If .Column > maxcol Then maxcol = .Column
If .Row < minlig Then minlig = .Row
lig = 0
lig = .Find("*", , xlValues, , xlByRows, xlPrevious).Row
'lig = .Find("*", , xlFormulas, , xlByRows, xlPrevious).Row 'autre possibilité
If lig > maxlig Then maxlig = lig
End With
End If
Next
Range(Cells(minlig, mincol), Cells(maxlig, maxcol)).Select
'If maxlig = 0 Then MsgBox "Aucune sélection possible..." 'facultatif
End Sub
Call SelectColonnes("Colonne", 2, 6)