Récupération d'une variable
E
Bonjour,
j'essaye de peaufiner ce code.
Lorsque l'on me demande un nombre de colonne, je le reporte comme variable nbcol.
Comment faire pour que la lettre de la colonne corresponde au nombre de colonne à cet endroit par rapport au modèle GAB_1 :
Range("C3").AutoFill Range("C3:I3"), xlFillSeries en admettant que la réponse soit 7, la lettre devrait être J
Sub Import_DATA()
Dim nbcol As Integer
nbcol = Application.InputBox("Nombre de colonne(s) à créer ?", "Import de données", Type:=1)
If nbcol = "0" Then
MsgBox "Import de données annulé"
Exit Sub
Else
Dim LigDep As Long, LigPlan As Long, LigBd As Long
Dim Cel As Range
Dim Bd As Worksheet
Dim Groupe As Integer
Dim I As Integer, K As Integer
Application.ScreenUpdating = False
Set Bd = Sheets("Index")
Bd.[A1].CurrentRegion.Sort Key1:=Bd.Range("K2"), Order1:=xlAscending, _
Key2:=Bd.Range("H2"), Order2:=xlAscending, _
Key3:=Bd.Range("F2"), Order3:=xlAscending, Header:=xlGuess
LigBd = 2
Do While LigBd <= Bd.[A65000].End(xlUp).Row
id_rgp = Bd.Cells(LigBd, 1) ' Premier id_rgp
Groupe = 0
LigDep = LigBd
Do While Bd.Cells(LigBd, 1) = id_rgp 'parcours id_rgp traité
'If Bd.Range("H" & LigBd) > Groupe * 6 Then
If Bd.Range("H" & LigBd) > Groupe * nbcol Then
Groupe = Groupe + 1
Sheets("GAB_1").Copy after:=Sheets(Sheets.Count)
ActiveSheet.Name = Format(LigBd, "00000") & id_rgp & "_" & Format(Groupe, "00") & "_1"
Range("A1").Value = id_rgp
'Range("K1").Value = nbcol
'Range("C3") = (Groupe * 6) - 5
Range("C3") = (Groupe * nbcol) - (nbcol - 1)
Range("C3").AutoFill Range("C3:I3"), xlFillSeries
End If
id_arbo = Bd.Cells(LigBd, 6)
Set Cel = Columns("A").Find(what:=id_arbo, LookIn:=xlValues, lookat:=xlWhole)
If Not Cel Is Nothing Then
LigPlan = Cel.Row
id_colonne = Bd.Cells(LigBd, 8)
Data = Bd.Cells(LigBd, 10)
Q = Application.Match(id_colonne, [CodesConges], 0)
If Not IsError(Q) Then Cells(LigPlan, Q + 2) = Data
End If
LigBd = LigBd + 1
Loop
Groupe = 0
LigBd = LigDep
Do While Bd.Cells(LigBd, 1) = id_rgp 'parcours id_rgp traité
If Bd.Range("H" & LigBd) > Groupe * 6 Then
Groupe = Groupe + 1
Sheets("GAB_1").Copy after:=Sheets(Sheets.Count)
ActiveSheet.Name = Format(LigBd, "00000") & id_rgp & "_" & Format(Groupe, "00") & "_2"
Range("A1").Value = id_rgp
Range("K1").Value = nbcol
Range("C3") = (Groupe * 6) - 5
Range("C3").AutoFill Range("C3:H3"), xlFillSeries
End If
id_arbo = Bd.Cells(LigBd, 6)
Set Cel = Columns("A").Find(what:=id_arbo, LookIn:=xlValues, lookat:=xlWhole)
If Not Cel Is Nothing Then
LigPlan = Cel.Row
id_colonne = Bd.Cells(LigBd, 8)
Data = Bd.Cells(LigBd, 10)
Q = Application.Match(id_colonne, [CodesConges], 0)
If Not IsError(Q) Then Cells(LigPlan, Q + 2) = Data
End If
LigBd = LigBd + 1
Loop
Loop
' Tri des feuilles
For I = 4 To Sheets.Count
For K = 4 To I - 1
If UCase(Sheets(I).Name) < UCase(Sheets(K).Name) Then
Sheets(I).Move Before:=Sheets(K)
Exit For
End If
Next K
Next I
For I = 4 To Sheets.Count
With Sheets(I)
.Name = Mid(.Name, 6)
End With
Next I
ThisWorkbook.Save
Application.Quit
End If
End Sub
' Utilisée pour le debogage
Sub SuppressionFeuilles()
Dim I As Integer
With Application
.ScreenUpdating = False
.DisplayAlerts = False
End With
For I = Sheets.Count To 4 Step -1
Sheets(I).Delete
Next I
Application.DisplayAlerts = True
End Sub
Merci de votre contribution
Bonjour
Remplaces la ligne
Range("C3").AutoFill Range("C3:I3"), xlFillSeries
par cette ligne
Range("C3").AutoFill Range("C3").Resize(, nbcol), xlFillSeries
E
Comme d'habitude.
Merci