1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| Option Explicit
Option Base 1
Sub test()
Dim x As Integer, f As String, z As Integer, deb() As Integer, fin() As Integer, _
cold As Integer, colf As Integer, mes As Range, ch As String, separ As String
'*****************************************************************************************************
'alimente les deux tableaux debut et fin des noms à définir
z = 1
ReDim deb(2)
ReDim fin(2)
deb(1) = 2
For x = 3 To ActiveSheet.UsedRange.Rows.Count
If Range("a" & x).Interior.ColorIndex = 41 Then
deb(z + 1) = Range("a" & x).Row
fin(z) = Range("a" & x - 1).Row
z = z + 1
ReDim Preserve deb(z + 1)
ReDim Preserve fin(z + 1)
End If
Next x
fin(z) = ActiveSheet.UsedRange.Rows.Count
Set mes = Application.InputBox("Choix de cellule(s)", Type:=8) 'message pour choisir le départ
If mes.Column < 4 Then: cold = 1: colf = 3: ch = ""
If mes.Column >= 4 Then: cold = 4: colf = 100: ch = "1"
If mes.Column > 100 Then: cold = 101: colf = 200: ch = "2"
For x = 1 To 6
separ = Replace(Range("a" & deb(x)).Value, "-", "_")
f = "" & "=Sheet1!R" & deb(x) & "C" & cold & ":R" & fin(x) & "C" & colf & ""
ActiveWorkbook.Names.Add Name:=separ & ch, RefersToR1C1:=f
Next x
End Sub |
Partager