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 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620
|
AjoutBatDynamique
Sub AjouterBatiment1()
Dim wsConsoModele As Worksheet, wsGestion As Worksheet, wsConsommations As Worksheet
Dim wsTurpeAvant As Worksheet, wsTurpeApres As Worksheet
Dim newSheetConso As Worksheet, newSheetTurpeAvant As Worksheet, newSheetTurpeApres As Worksheet
Dim typeTurpe As String, nomBatiment As String
Dim i As Long
Dim calcState As XlCalculation
Dim screenUpdateState As Boolean, eventsState As Boolean
Dim colRose As Long, colJaune As Long
Dim colAvantLettre As String
Dim rowBldg As Long
' Sauvegarde des états
screenUpdateState = Application.ScreenUpdating
eventsState = Application.EnableEvents
calcState = Application.Calculation
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
Set wsConsoModele = Sheets("MODELE_Conso")
Set wsGestion = Sheets("Gestion des bâtiments")
Set wsConsommations = Sheets("Consommations")
' Lancer le UserForm
UserFormAjoutBatiment.Show
nomBatiment = nomBatimentSaisi
typeTurpe = typeRaccordementChoisi
If nomBatiment = "" Or typeTurpe = "" Then GoTo Fin
' Vérifie si le bâtiment existe déjà
For i = 3 To 20
If wsGestion.Cells(i, 1).Value = nomBatiment Then
MsgBox "Le nom """ & nomBatiment & """ existe déjà dans la feuille Gestion des bâtiments.", vbExclamation
GoTo Fin
End If
Next i
' Choix du modèle TURPE
If typeTurpe = "HTA" Then
Set wsTurpeAvant = Sheets("MODELE_TurpeHTAAvant")
Set wsTurpeApres = Sheets("MODELE_TurpeHTAapres")
Else
Set wsTurpeAvant = Sheets("MODELE_TurpeBTAvant")
Set wsTurpeApres = Sheets("MODELE_TurpeBTapres")
End If
' Duplication des feuilles
' Copie de la feuille MODELE_Conso
With Sheets("MODELE_Conso")
.Visible = xlSheetVisible
.Copy After:=Sheets(Sheets.Count)
.Visible = xlSheetHidden ' <<<< Permet l'affichage via clic droit
End With
Set newSheetConso = ActiveSheet
newSheetConso.Name = nomBatiment & "_Conso"
If typeTurpe = "HTA" Then
' Turpe HTA Avant
With Sheets("MODELE_TurpeHTAAvant")
.Visible = xlSheetVisible
.Copy After:=Sheets(Sheets.Count)
.Visible = xlSheetHidden
End With
Set newSheetTurpeAvant = ActiveSheet
newSheetTurpeAvant.Name = nomBatiment & "_TurpeAvant"
' Turpe HTA Après
With Sheets("MODELE_TurpeHTAapres")
.Visible = xlSheetVisible
.Copy After:=Sheets(Sheets.Count)
.Visible = xlSheetHidden
End With
Set newSheetTurpeApres = ActiveSheet
newSheetTurpeApres.Name = nomBatiment & "_TurpeApres"
ElseIf typeTurpe = "BT" Then
' Turpe BT Avant
With Sheets("MODELE_TurpeBTAvant")
.Visible = xlSheetVisible
.Copy After:=Sheets(Sheets.Count)
.Visible = xlSheetHidden
End With
Set newSheetTurpeAvant = ActiveSheet
newSheetTurpeAvant.Name = nomBatiment & "_TurpeAvant"
' Turpe BT Après
With Sheets("MODELE_TurpeBTapres")
.Visible = xlSheetVisible
.Copy After:=Sheets(Sheets.Count)
.Visible = xlSheetHidden
End With
Set newSheetTurpeApres = ActiveSheet
newSheetTurpeApres.Name = nomBatiment & "_TurpeApres"
End If
' Mise à jour des formules
Call UpdateFormulas(newSheetTurpeAvant, typeTurpe, "MODELE_Conso", newSheetConso.Name)
Call UpdateFormulas(newSheetTurpeApres, typeTurpe, "MODELE_Conso", newSheetConso.Name)
' Ajout dans "Gestion des bâtiments"
Dim ligneTrouvee As Boolean
ligneTrouvee = False
For rowBldg = 3 To 20
If wsGestion.Cells(rowBldg, 1).Value = "" Then
wsGestion.Cells(rowBldg, 1).Value = nomBatiment
wsGestion.Cells(rowBldg, 2).Value = typeTurpe
ligneTrouvee = True
Exit For
End If
Next rowBldg
If Not ligneTrouvee Then
MsgBox "Le tableau est plein (lignes 3 à 20). Impossible dajouter un nouveau bâtiment.", vbExclamation
GoTo Fin
End If
' Déterminer la première colonne disponible à partir de K (col 11)
colRose = Application.Max(11, wsConsommations.Cells(1, wsConsommations.Columns.Count).End(xlToLeft).Column + 1)
colJaune = colRose + 1
colAvantLettre = Split(wsConsommations.Cells(1, colJaune - 1).Address, "$")(1)
' Entêtes formatées
With wsConsommations.Cells(1, colRose)
.Value = nomBatiment
.Interior.Color = RGB(255, 192, 203)
.Font.Bold = True
.HorizontalAlignment = xlCenter
.Borders.Weight = xlThin
End With
With wsConsommations.Cells(1, colJaune)
.Value = nomBatiment & "_PV"
.Interior.Color = RGB(255, 255, 153)
.Font.Bold = True
.HorizontalAlignment = xlCenter
.Borders.Weight = xlThin
End With
' Colonne rose : données G3:G8762 de la feuille Conso
For i = 3 To 8762
wsConsommations.Cells(i - 1, colRose).Formula = "='" & newSheetConso.Name & "'!$G" & i
With wsConsommations.Cells(i - 1, colRose)
.Interior.Color = RGB(255, 192, 203)
.Borders.Weight = xlThin
End With
Next i
' Colonne jaune : formule personnalisée simple (ex: décalage ou 0)
' Colonne jaune avec formule dynamique
For i = 2 To 8762
If colJaune = 12 Then ' Colonne L
wsConsommations.Cells(i, colJaune).FormulaLocal = "=SI(K" & i & "-$E" & i & "<0;0;K" & i & "-$E" & i & ")"
Else
wsConsommations.Cells(i, colJaune).FormulaLocal = "=SI(($F" & i & "-$K" & i & ")=0;0;SI((" & colAvantLettre & i & "-(" & colAvantLettre & i & "/($F" & i & "-$K" & i & "))*$H" & i & ")<0;0;(" & colAvantLettre & i & "-(" & colAvantLettre & i & "/($F" & i & "-$K" & i & "))*$H" & i & ")))"
End If
With wsConsommations.Cells(i, colJaune)
.Interior.Color = RGB(255, 255, 153)
.Borders.Weight = xlThin
End With
Next i
' Feuille Conso : colonne H = formule vers colonne jaune dans Consommations
For i = 3 To 8762
newSheetConso.Cells(i, 8).Formula = "='Consommations'!" & wsConsommations.Cells(i - 1, colJaune).Address
Next i
Fin:
Application.ScreenUpdating = screenUpdateState
Application.EnableEvents = eventsState
Application.Calculation = calcState
End Sub
Sub UpdateFormulas(ws As Worksheet, typeTurpe As String, oldSheetName As String, newSheetName As String)
Dim cell As Range
On Error Resume Next
If typeTurpe = "HTA" Then
For Each cell In Union(ws.Range("B25:F36"), ws.Range("B44:F55")).SpecialCells(xlCellTypeFormulas)
cell.Formula = Replace(cell.Formula, oldSheetName, newSheetName)
Next cell
ElseIf typeTurpe = "BT" Then
For Each cell In ws.Range("B26:F37").SpecialCells(xlCellTypeFormulas)
cell.Formula = Replace(cell.Formula, oldSheetName, newSheetName)
Next cell
End If
On Error GoTo 0
End Sub
AjoutBatStatique
Sub AjouterBatiment2()
Dim wsConsoModele As Worksheet, wsGestion As Worksheet, wsConsommations As Worksheet
Dim wsTurpeAvant As Worksheet, wsTurpeApres As Worksheet
Dim newSheetConso As Worksheet, newSheetTurpeAvant As Worksheet, newSheetTurpeApres As Worksheet
Dim typeTurpe As String, nomBatiment As String
Dim i As Long
Dim calcState As XlCalculation
Dim screenUpdateState As Boolean, eventsState As Boolean
Dim colRose As Long, colJaune As Long
Dim colAvantLettre As String
Dim rowBldg As Long
' Sauvegarde des états
screenUpdateState = Application.ScreenUpdating
eventsState = Application.EnableEvents
calcState = Application.Calculation
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
Set wsConsoModele = Sheets("MODELE_Conso")
Set wsGestion = Sheets("Gestion des bâtiments")
Set wsConsommations = Sheets("Consommations")
' Lancer le UserForm
UserFormAjoutBatiment.Show
nomBatiment = nomBatimentSaisi
typeTurpe = typeRaccordementChoisi
If nomBatiment = "" Or typeTurpe = "" Then GoTo Fin
' Vérifie si le bâtiment existe déjà
For i = 3 To wsGestion.Cells(wsGestion.Rows.Count, 1).End(xlUp).Row
If wsGestion.Cells(i, 1).Value = nomBatiment Then
MsgBox "Le nom """ & nomBatiment & """ existe déjà.", vbExclamation
GoTo Fin
End If
Next i
' Choix du modèle TURPE
If typeTurpe = "HTA" Then
Set wsTurpeAvant = Sheets("MODELE_TurpeHTAAvant")
Set wsTurpeApres = Sheets("MODELE_TurpeHTAapres")
Else
Set wsTurpeAvant = Sheets("MODELE_TurpeBTAvant")
Set wsTurpeApres = Sheets("MODELE_TurpeBTapres")
End If
' Duplication des feuilles
' Copie de la feuille MODELE_Conso
With Sheets("MODELE_Conso")
.Visible = xlSheetVisible
.Copy After:=Sheets(Sheets.Count)
.Visible = xlSheetHidden ' <<<< Permet l'affichage via clic droit
End With
Set newSheetConso = ActiveSheet
newSheetConso.Name = nomBatiment & "_Conso"
If typeTurpe = "HTA" Then
' Turpe HTA Avant
With Sheets("MODELE_TurpeHTAAvant")
.Visible = xlSheetVisible
.Copy After:=Sheets(Sheets.Count)
.Visible = xlSheetHidden
End With
Set newSheetTurpeAvant = ActiveSheet
newSheetTurpeAvant.Name = nomBatiment & "_TurpeAvant"
' Turpe HTA Après
With Sheets("MODELE_TurpeHTAapres")
.Visible = xlSheetVisible
.Copy After:=Sheets(Sheets.Count)
.Visible = xlSheetHidden
End With
Set newSheetTurpeApres = ActiveSheet
newSheetTurpeApres.Name = nomBatiment & "_TurpeApres"
ElseIf typeTurpe = "BT" Then
' Turpe BT Avant
With Sheets("MODELE_TurpeBTAvant")
.Visible = xlSheetVisible
.Copy After:=Sheets(Sheets.Count)
.Visible = xlSheetHidden
End With
Set newSheetTurpeAvant = ActiveSheet
newSheetTurpeAvant.Name = nomBatiment & "_TurpeAvant"
' Turpe BT Après
With Sheets("MODELE_TurpeBTapres")
.Visible = xlSheetVisible
.Copy After:=Sheets(Sheets.Count)
.Visible = xlSheetHidden
End With
Set newSheetTurpeApres = ActiveSheet
newSheetTurpeApres.Name = nomBatiment & "_TurpeApres"
End If
' Mise à jour des formules
Call UpdateFormulas(newSheetTurpeAvant, typeTurpe, "MODELE_Conso", newSheetConso.Name)
Call UpdateFormulas(newSheetTurpeApres, typeTurpe, "MODELE_Conso", newSheetConso.Name)
' Ajout dans "Gestion des bâtiments"
rowBldg = wsGestion.Cells(wsGestion.Rows.Count, 1).End(xlUp).Row + 1
wsGestion.Cells(rowBldg, 1).Value = nomBatiment
wsGestion.Cells(rowBldg, 2).Value = typeTurpe
' Déterminer la première colonne disponible à partir de K (col 11)
colRose = Application.Max(11, wsConsommations.Cells(1, wsConsommations.Columns.Count).End(xlToLeft).Column + 1)
colJaune = colRose + 1
colAvantLettre = Split(wsConsommations.Cells(1, colJaune - 1).Address, "$")(1)
' Entêtes formatées
With wsConsommations.Cells(1, colRose)
.Value = nomBatiment
.Interior.Color = RGB(255, 192, 203)
.Font.Bold = True
.HorizontalAlignment = xlCenter
.Borders.Weight = xlThin
End With
With wsConsommations.Cells(1, colJaune)
.Value = nomBatiment & "_PV"
.Interior.Color = RGB(255, 255, 153)
.Font.Bold = True
.HorizontalAlignment = xlCenter
.Borders.Weight = xlThin
End With
' Colonne rose : données G3:G8762 de la feuille Conso
For i = 3 To 8762
wsConsommations.Cells(i - 1, colRose).Formula = "='" & newSheetConso.Name & "'!$G" & i
With wsConsommations.Cells(i - 1, colRose)
.Interior.Color = RGB(255, 192, 203)
.Borders.Weight = xlThin
End With
Next i
' Colonne jaune : formule personnalisée simple (ex: décalage ou 0)
' Colonne jaune avec formule dynamique
For i = 2 To 8762
If colJaune = 12 Then ' Colonne L
wsConsommations.Cells(i, colJaune).FormulaLocal = "=SI(K" & i & "-$E" & i & "<0;0;K" & i & "-$E" & i & ")"
Else
wsConsommations.Cells(i, colJaune).FormulaLocal = "=SI(" & colAvantLettre & i & "-RECHERCHEV(" & colAvantLettre & "$1;'Gestion des bâtiments'!$A$1:$F$14;5;FAUX())*$H" & i & "<0;0;" & colAvantLettre & i & "-RECHERCHEV(" & colAvantLettre & "$1;'Gestion des bâtiments'!$A$1:$F$14;5;FAUX())*$H" & i & ")"
End If
With wsConsommations.Cells(i, colJaune)
.Interior.Color = RGB(255, 255, 153)
.Borders.Weight = xlThin
End With
Next i
' Feuille Conso : colonne H = formule vers colonne jaune dans Consommations
For i = 3 To 8762
newSheetConso.Cells(i, 8).Formula = "='Consommations'!" & wsConsommations.Cells(i - 1, colJaune).Address
Next i
Fin:
Application.ScreenUpdating = screenUpdateState
Application.EnableEvents = eventsState
Application.Calculation = calcState
End Sub
Sub UpdateFormulas(ws As Worksheet, typeTurpe As String, oldSheetName As String, newSheetName As String)
Dim cell As Range
On Error Resume Next
If typeTurpe = "HTA" Then
For Each cell In Union(ws.Range("B25:F36"), ws.Range("B44:F55")).SpecialCells(xlCellTypeFormulas)
cell.Formula = Replace(cell.Formula, oldSheetName, newSheetName)
Next cell
ElseIf typeTurpe = "BT" Then
For Each cell In ws.Range("B26:F37").SpecialCells(xlCellTypeFormulas)
cell.Formula = Replace(cell.Formula, oldSheetName, newSheetName)
Next cell
End If
On Error GoTo 0
End Sub
Supprimer des bâtiments
Sub LancerUserFormSuppression()
UserFormSuppression.Show
End Sub
Sub SupprimerBatimentDepuisModule(nomBatiment As String)
Dim wsConsommations As Worksheet, wsGestion As Worksheet, wsBldgConso As Worksheet
Dim tempSheet As Worksheet, feuille As Worksheet
Dim colRose As Long, colJaune As Long, lastCol As Long, lastRow As Long
Dim i As Long, col As Long, ligne As Long, destCol As Long
Dim ligneTrouvee As Long, largeurRose As Double
Dim screenUpdateState As Boolean, eventsState As Boolean
Dim calcState As XlCalculation
' Sauvegarde des états Excel
screenUpdateState = Application.ScreenUpdating
eventsState = Application.EnableEvents
calcState = Application.Calculation
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
Set wsConsommations = Sheets("Consommations")
Set wsGestion = Sheets("Gestion des bâtiments")
' Vérifie si la feuille _Conso existe
On Error Resume Next
Set wsBldgConso = Sheets(nomBatiment & "_Conso")
On Error GoTo 0
If wsBldgConso Is Nothing Then
MsgBox "Feuille """ & nomBatiment & "_Conso"" introuvable.", vbExclamation
GoTo Fin
End If
' Trouver la colonne rose
lastCol = wsConsommations.Cells(1, wsConsommations.Columns.Count).End(xlToLeft).Column
colRose = 0
For col = 11 To lastCol
If wsConsommations.Cells(1, col).Value = nomBatiment Then
colRose = col
Exit For
End If
Next col
If colRose = 0 Then
MsgBox "Colonnes """ & nomBatiment & """ introuvables.", vbExclamation
GoTo Fin
End If
colJaune = colRose + 1
' Créer nouvelle feuille TEMP après Gestion des bâtiments
Sheets.Add After:=wsGestion
Set tempSheet = ActiveSheet
tempSheet.Name = "Consommations_TEMP"
lastRow = wsConsommations.Cells(wsConsommations.Rows.Count, "A").End(xlUp).Row
' Copier colonnes fixes A:J
wsConsommations.Range("A1:J" & lastRow).Copy Destination:=tempSheet.Range("A1")
' Copier colonnes dynamiques sauf rose + jaune
destCol = 11
For i = 11 To lastCol
If i <> colRose And i <> colJaune Then
wsConsommations.Columns(i).Copy Destination:=tempSheet.Columns(destCol)
destCol = destCol + 1
End If
Next i
' Supprimer ancienne feuille Consommations et renommer la nouvelle
Application.DisplayAlerts = False
wsConsommations.Delete
tempSheet.Name = "Consommations"
Application.DisplayAlerts = True
' Uniformiser largeur colonnes roses/jaunes restantes
lastCol = tempSheet.Cells(1, tempSheet.Columns.Count).End(xlToLeft).Column
For i = 11 To lastCol Step 2
If tempSheet.Cells(1, i).Value <> "" And tempSheet.Cells(1, i + 1).Value <> "" Then
largeurRose = tempSheet.Columns(i).ColumnWidth
tempSheet.Columns(i + 1).ColumnWidth = largeurRose
End If
Next i
' Supprimer les feuilles du bâtiment
Application.DisplayAlerts = False
On Error Resume Next
Sheets(nomBatiment & "_Conso").Delete
Sheets(nomBatiment & "_TurpeAvant").Delete
Sheets(nomBatiment & "_TurpeApres").Delete
On Error GoTo 0
Application.DisplayAlerts = True
' Nettoyer Gestion des bâtiments (effacer A:E sans supprimer la ligne)
ligneTrouvee = 0
For i = 3 To 20
If wsGestion.Cells(i, 1).Value = nomBatiment Then
ligneTrouvee = i
Exit For
End If
Next i
If ligneTrouvee > 0 Then
wsGestion.Range("A" & ligneTrouvee & ":E" & ligneTrouvee).ClearContents
If ligneTrouvee < 20 Then
wsGestion.Range("A" & (ligneTrouvee + 1) & ":E20").Copy
wsGestion.Range("A" & ligneTrouvee).Resize(20 - ligneTrouvee, 5).Value = _
wsGestion.Range("A" & (ligneTrouvee + 1) & ":E20").Value
wsGestion.Range("A" & (ligneTrouvee + 1) & ":E20").ClearContents
Application.CutCopyMode = False
End If
End If
' ?? Réécrire colonne H dans chaque feuille _Conso restante
Dim nomPV As String, colPV As Long
For Each feuille In ThisWorkbook.Worksheets
If feuille.Name Like "*_Conso" Then
nomPV = Replace(feuille.Name, "_Conso", "_PV")
colPV = 0
' Trouver colonne jaune correspondante dans nouvelle feuille "Consommations"
For col = 11 To tempSheet.Cells(1, tempSheet.Columns.Count).End(xlToLeft).Column
If tempSheet.Cells(1, col).Value = nomPV Then
colPV = col
Exit For
End If
Next col
' Si trouvée, on met à jour la colonne H
If colPV > 0 Then
For ligne = 3 To 8762
feuille.Cells(ligne, 8).Formula = "='Consommations'!" & tempSheet.Cells(ligne - 1, colPV).Address
Next ligne
End If
End If
Next feuille
MsgBox "? Bâtiment """ & nomBatiment & """ supprimé proprement. Références mises à jour.", vbInformation
Fin:
' Restauration des états Excel
Application.ScreenUpdating = screenUpdateState
Application.EnableEvents = eventsState
Application.Calculation = calcState
End Sub
DeclPublicBatNometRaccordement
Public nomBatimentSaisi As String
Public typeRaccordementChoisi As String
Public typeFeuille As String
UserFormAjoutBatiment
Private Sub CommandButtonOK_Click()
' Vérifier que le nom est bien rempli
If Trim(TextBoxNom.Value) = "" Then
MsgBox "Veuillez entrer un nom de bâtiment.", vbExclamation
Exit Sub
End If
' Vérifier que le type de raccordement est bien choisi
If ComboBoxType.Value <> "HTA" And ComboBoxType.Value <> "BT" Then
MsgBox "Veuillez choisir un type de raccordement (HTA ou BT).", vbExclamation
Exit Sub
End If
' Tout est OK, on stocke les valeurs dans des variables publiques
nomBatimentSaisi = TextBoxNom.Value
typeRaccordementChoisi = ComboBoxType.Value
Me.Hide
End Sub
Private Sub UserForm_Initialize()
' Remplir la ComboBox avec HTA et BT
ComboBoxType.Clear
ComboBoxType.AddItem "HTA"
ComboBoxType.AddItem "BT"
' Vider les champs
TextBoxNom.Value = ""
' TextBoxPourcentage.Value = ""
' ' Récupérer le pourcentage déjà utilisé
' Dim wsGestion As Worksheet
' Dim i As Long, sommeExistante As Double
' Set wsGestion = Worksheets("Gestion des bâtiments")
'
' sommeExistante = 0
' For i = 2 To wsGestion.Cells(wsGestion.Rows.Count, "F").End(xlUp).Row
' If IsNumeric(wsGestion.Cells(i, 6).Value) Then
' sommeExistante = sommeExistante + CDbl(wsGestion.Cells(i, 6).Value)
' End If
' Next i
'
' ' Afficher le pourcentage restant
' LabelRestant.Caption = "Pourcentage restant : " & (100 - sommeExistante) & "%"
'
' ' Si c'est le premier bâtiment (aucun pourcentage existant), on masque le champ
' If sommeExistante = 0 Then
' LabelPourcentage.Visible = False
' TextBoxPourcentage.Visible = False
' LabelRestant.Visible = False
' Else
' LabelPourcentage.Visible = True
' TextBoxPourcentage.Visible = True
' LabelRestant.Visible = True
' End If
End Sub
Private Sub CommandButtonAnnuler_Click()
Unload Me
End Sub
UserFormSuppression
Private Sub UserForm_Initialize()
Dim ws As Worksheet
Dim lastRow As Long
Dim i As Long
Dim nom As String
Set ws = ThisWorkbook.Sheets("Gestion des bâtiments")
lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
For i = 3 To 20
nom = ws.Cells(i, 1).Value
If nom <> "" Then
ComboBoxBatiments.AddItem nom
End If
Next i
End Sub
Private Sub CommandButtonAnnuler_Click()
Unload Me
End Sub
Private Sub CommandButtonSupprimer_Click()
If ComboBoxBatiments.Value = "" Then
MsgBox "Veuillez sélectionner un bâtiment à supprimer.", vbExclamation
Exit Sub
End If
Dim confirmation As VbMsgBoxResult
confirmation = MsgBox("Êtes-vous sûr de vouloir supprimer le bâtiment '" & ComboBoxBatiments.Value & "' ?", vbYesNo + vbQuestion, "Confirmation")
If confirmation = vbYes Then
Call SupprimerBatimentDepuisModule(ComboBoxBatiments.Value)
Unload Me
End If
End Sub |