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
| Private Sub btn_lot_ajou_Click()
Dim c As Range, derlig As Long
If Text_lot_num.Value = "" Then
If MsgBox("Vous devez ABSOLUMENT attribuer un Numéro de Lot", vbYesNo, "Titre de la MsgBox") = vbYes Then
'procédure si click sur Oui
Text_lot_num.SetFocus
Exit Sub
Else
Use_lot.Hide
End If
Else 'si c'est un numérique, tu peux le vérifier ici et ajouter une condition
'On cherche la valeur dans la colonne A
Sheets("Lots").Activate
derlig = Split(ActiveSheet.UsedRange.Address, "$")(4)
With Sheets("Lots").Range("a1:a" & derlig)
Set c = .Find(Text_lot_num.Value, LookIn:=xlValues, Lookat:=xlWhole)
'Si elle existe, on efface Text_lot_num et on replace le focus
If Not c Is Nothing Then
MsgBox "Code déjà existant, Veuillez resaisir un autre Code. Merci"
Me.Text_lot_num = ""
Me.Text_lot_num.SetFocus
Exit Sub
End If
End With
End If
' selectionne la feuille lots
Sheets("Lots").Select
'routine sur l'inscription des valeurs dans la ligne premiere vide
ligne = 2
Range("A" & ligne).Select
Do While Range("A" & ligne).Value <> ""
ligne = ligne + 1
Loop
' copie les valeurs des zones de saisie dans la feuille lots
Range("A" & ligne).Value = Text_lot_num.Value
Range("B" & ligne).Value = Text_lot_bai.Value
Range("C" & ligne).Value = Text_lot_loc.Value
Range("D" & ligne).Value = Text_lot_adr.Value
Range("E" & ligne).Value = Text_lot_cod.Value
Range("F" & ligne).Value = Comb_lot_com.Value
Range("G" & ligne).Value = Text_lot_tel.Value
Range("H" & ligne).Value = Text_lot_fax.Value
Range("I" & ligne).Value = Text_lot_por.Value
Range("J" & ligne).Value = Text_lot_mel.Value
Range("K" & ligne).Value = Text_lot_comm.Value
' remet les valeurs des zones de saisie a vide
Text_lot_num.Value = ""
Text_lot_bai.Value = ""
Text_lot_loc.Value = ""
Text_lot_adr.Value = ""
Text_lot_cod.Value = ""
Comb_lot_com.Value = ""
Text_lot_tel.Value = ""
Text_lot_fax.Value = ""
Text_lot_por.Value = ""
Text_lot_mel.Value = ""
Text_lot_comm.Value = ""
'remet le curseur dans la zone choisie
Text_lot_num.SetFocus
' trie et dedoublonne la colonne c ( communes) et la colonne E (locataires)
' tri
worksheets("Listes").Select
Columns("c:c").Select
ActiveSheet.Range("$c$1:$c$5000").RemoveDuplicates Columns:=1, Header:=xlYes
' dedoublonnage
Range("c2:c50000").Select
ActiveWorkbook.worksheets("Listes").Sort.SortFields.Clear
ActiveWorkbook.worksheets("Listes").Sort.SortFields.Add Key:=Range("c2:c5000") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.worksheets("Listes").Sort
.SetRange Range("c2:c5000")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
' tri
worksheets("Listes").Select
Columns("e:e").Select
ActiveSheet.Range("$e$1:$e$5000").RemoveDuplicates Columns:=1, Header:=xlYes
' dedoublonnage
Range("e2:e50000").Select
ActiveWorkbook.worksheets("Listes").Sort.SortFields.Clear
ActiveWorkbook.worksheets("Listes").Sort.SortFields.Add Key:=Range("e2:e5000") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.worksheets("Listes").Sort
.SetRange Range("e2:e5000")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
'tri de la table des lots
worksheets("Lots").Select
Application.Goto Reference:="TableLots"
ActiveWorkbook.worksheets("Lots").Sort.SortFields.Clear
ActiveWorkbook.worksheets("Lots").Sort.SortFields.Add Key:=Range("A2:A5000"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.worksheets("Lots").Sort
.SetRange Range("A2:K5000")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
ActiveWorkbook.Save
Sheets("accueil").Select
End Sub |
Partager