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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
| Option Explicit
Const cst_Restit_CA = 1
Const cst_Restit_Presta = 2
Const cst_Restit_Insee = 3
Const cst_Restit_TypeW = 4
Const cst_Restit_CP = 5
Const cst_Restit_TechB = 6
Const cst_Restit_OSR = 7
Const cst_Restit_Client = 8
Const cst_Restit_NumLigne = 11
Sub Macro()
Dim lige As Integer 'numero de ligne export
Dim lige1 As Integer
Dim lige2 As Integer
Dim ligca2 As Integer
Dim test1 As Boolean
Dim test2 As Boolean
Dim test3 As Boolean
Dim test4 As Boolean
Dim testimp As Boolean
Dim nmp() As String
Dim nmc() As String
Dim bdtp() As String
Dim ipimp() As String
Dim typ(2) As Integer
Dim prio(1 To 7, 4 To 14) As String
Dim colnp(4 To 13) As Integer
'Dim coln1 As Integer
'Dim coln2 As Integer
'Dim coln3 As Integer
'Dim coln4 As Integer
'Dim coln5 As Integer
'Dim coln6 As Integer
'Dim coln7 As Integer
'Dim coln8 As Integer
'Dim coln9 As Integer
'Dim coln10 As Integer
'Dim coln18 As Integer
Dim nm1 As String
Dim nm2 As String
Dim nm3 As String
Dim nm4 As String
Dim nmprest As String
Dim nmca As String
Dim a As Integer
Dim b As Integer
Dim PlageData As Range, aCell As Range
Dim lgLigne As Long
Dim lgData As Long
Dim NbrLigne
restit = cherchcol("", True, False)
'Pour aider à la lecture du code, les constantes permettent de repérer de suite de quoi il s'agit, elles seront utilisé directement plus bas dans le code
'Je n'ai pas compris l'utilité de restit()
' coln1 = restit(cst_Restit_CA) 'ca
' coln2 = restit(cst_Restit_Presta) 'presta
' coln3 = restit(cst_Restit_OSR) 'osr
' lige = restit(cst_Restit_NumLigne)
' coln4 = restit(cst_Restit_TypeW) ' 4=type travaux ,
' coln5 = restit(cst_Restit_CP) ' 5=consignes particulières,
' coln6 = restit(cst_Restit_TechB) ' 6=technique brcht
' 'coln7=restit()
' coln18 = restit(cst_Restit_Client) ' client
' coln10 = restit(cst_Restit_Insee) ' 3 = insee,
'definition de la liste presta
'Si tu as la possibilité le mieux serait de placer les données de dbpresta sous forme de tableau structuré, ça alégerait grandement ton code (et sa fiabilité)
'A défaut tu peux faire comme ça
'On pointe la feuille de travail
With ThisWorkbook.Sheets("bdpresta")
'On pointe la plage qui contient les données
Set PlageData = .Range(.Range("A6"), .Cells(.Rows.Count, "A").End(xlUp))
End With
'On redimensionne le tableau qui va recevoir les valeurs
'Inutile de faire un erase, le redim sans le mot clé preserve détruit le contenu du tableau
ReDim nmp(1 To PlageData.Rows.Count)
lgData = 1
'On boucle sur les cellules contenues dans la plage
For Each aCell In PlageData
nmp(lgData) = aCell.Value
Next
' lige1 = 6
' Do While Sheets("bdpresta").Range("a" & lige1).Value <> ""
' lige1 = lige1 + 1
' If lige1 = 10000 Then Exit Do
' Loop
' Erase nmp
' ReDim nmp(6 To lige1 - 1)
' For lige2 = 6 To lige1 - 1
' nmp(lige2) = Sheets("bdpresta").Cells(lige2, 1).Value
' Next lige2
'definition de la liste ca
With ThisWorkbook.Sheets("bdChargaff")
'On pointe la plage qui contient les données
Set PlageData = .Range(.Range("A4"), .Cells(.Rows.Count, "A").End(xlUp))
End With
'On redimensionne le tableau qui va recevoir les valeurs
'Inutile de faire un erase, le redim sans le mot clé preserve détruit le contenu du tableau
ReDim nmc(1 To PlageData.Rows.Count)
lgData = 1
'On boucle sur les cellules contenues dans la plage
For Each aCell In PlageData
nmc(lgData) = aCell.Value
Next
' lige1 = 4
' Do While Sheets("bdChargaff").Range("a" & lige1).Value <> ""
' lige1 = lige1 + 1
' If lige1 = 10000 Then Exit Do
' Loop
' Erase nmc
' ReDim nmc(4 To lige1 - 1)
' For lige2 = 4 To lige1 - 1
' nmc(lige2) = Sheets("bdChargaff").Cells(lige2, 3).Value & " " & Sheets("bdChargaff").Cells(lige2, 2).Value
' Next lige2
nmprest = Join(nmp, ";")
nmca = Join(nmc, ";")
'Pour la suite, je vois un maxi de 10000 lignes, il faudra faire une gestion du application.screenupdating pour accélérer le traitement
'On pointe la feuille Export
With ThisWorkbook.Sheets("export")
'On regarde le nombre de ligne à traiter (je suppose que la colonne 3 à toujours un contenu
NbrLigne = .Cells(.Rows.Count, restit(cst_Restit_Insee)).End(xlUp).Row
'On pointe le tableau complet
Set PlageData = .Range(.Cells(restit(cst_Restit_NumLigne), restit(cst_Restit_CA)), .Cells(NbrLigne, restit(cst_Restit_NumLigne)))
If Plage.Rows.Count > 10000 Then
MsgBox "TROP DE LIGNES A ANALYSER" & vbCrLf & "Contactez le concepteur - erreur saisman 1", vbCritical
Else
'On boucle sur les lignes de la plage
For lgLigne = 1 To Plage.Rows.Count
insee = .Cells(lgLigne, restit(cst_Restit_Insee)).Value
'*********************************insertion de la validation de données dans la case prestataire
With .Cells(lige, coln2).Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:=nmprest
'Inutile de remettre toutes les valeurs qui sont déjà celles par défaut
' .IgnoreBlank = True
' .InCellDropdown = True
' .InputTitle = ""
' .ErrorTitle = ""
' .InputMessage = ""
' .ErrorMessage = ""
' .ShowInput = True
' .ShowError = True
End With
'**************************insertion de la validation de données dans la case chargé d'affaires
With .Cells(lige, coln1).Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:=nmca
' .IgnoreBlank = True
' .InCellDropdown = True
' .ShowInput = True
' .ShowError = True
End With
'lige = lige + 1
' If lige = 10000 Then
' MsgBox "TROP DE LIGNES ANALYSES" & vbCrLf & "Contactez le concepteur - erreur saisman 1", vbCritical
' Exit Sub
' End If
Loop
End Sub |
Partager