' Cette procédure ouvre un userform lorsque l'on clique sur une des cellules de la colonne B à condition qu'il y ait une valeur sur la ligne.
' Ce userform affiche des données de la ligne concernée.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim i As Long, j As Long, xlgn As Long, xdlgn As Long, xcol As Long, xmttl As Double, DerCol As Long, nrlign As Long
If Application.Intersect(Target, Range("b5:b" & xdlgn)) Is Nothing Then
xdlgn = ActiveSheet.Range("C" & Rows.Count).End(xlUp).Row
xlgn = Target.Row
xcol = ActiveSheet.Cells(xlgn, Columns.Count).End(xlToLeft).Column
If ActiveSheet.Cells(xlgn, 6) < "01/01/1900" Then
MsgBox "Aucun Compte-titres ne figure sur cette ligne.", vbInformation, "COMPTES-TITRES"
Exit Sub
End If
UserForm2.TextBox1.Value = Cells(xlgn, 3).Value
UserForm2.TextBox2.Value = Cells(xlgn, 8).Value
UserForm2.TextBox3.Value = Cells(xlgn, 6).Value
UserForm2.TextBox4.Value = Cells(xlgn, 9).Value
UserForm2.TextBox4.Value = Format(UserForm2.TextBox4.Value, "### ##0.00")
UserForm2.TextBox5.Value = Cells(xlgn, xcol).Value
UserForm2.TextBox5.Value = Format(UserForm2.TextBox5.Value, "### ##0.00")
UserForm2.TextBox6.Value = UserForm2.TextBox5.Value - UserForm2.TextBox4.Value
UserForm2.TextBox6.Value = Format(UserForm2.TextBox6.Value, "### ##0.00")
If UserForm2.TextBox6.Value < 0 Then
UserForm2.TextBox6.ForeColor = vbRed
End If
UserForm2.TextBox7.Value = Cells(xlgn, 5).Value
UserForm2.TextBox8.Value = Cells(xlgn, 4).Value
UserForm2.TextBox8.Value = Format(UserForm2.TextBox8.Value, "### ##0.00")
UserForm2.TextBox9.Value = UserForm2.TextBox5.Value - UserForm2.TextBox4.Value + UserForm2.TextBox8.Value
UserForm2.TextBox9.Value = Format(UserForm2.TextBox9.Value, "### ##0.00")
If UserForm2.TextBox9.Value < 0 Then
UserForm2.TextBox9.ForeColor = vbRed
End If
UserForm2.TextBox10.Value = Cells(2, 4).Value
Range("A3").Activate
UserForm2.Show
End If
If Application.Intersect(Target, Range("A5:A" & xdlgn)) Is Nothing Then
xdlgn = ActiveSheet.Range("C" & Rows.Count).End(xlUp).Row
xlgn = Target.Row
xcol = ActiveSheet.Cells(xlgn, Columns.Count).End(xlToLeft).Column
If ActiveSheet.Cells(xlgn, 6) < "01/01/1900" Then
MsgBox "Aucun Compte-titres ne figure sur cette ligne.", vbInformation, "COMPTES-TITRES"
Exit Sub
End If
'COPIER CERTAINES DONNEES DANS ARCHIVES
nrlign = sheets("ARCHIVES").Range("C" & Rows.Count).End(xlUp).Row + 1
Worksheets("CPTE_TITRES1").Cells(xlgn, 3).Value.Copy Worksheet("ARCHIVES").Cells(nrlign, 2).Value
' VIDER LE CONTENU DE LA LIGNE CONCERNEE DANS CPTE_TITRES1 EN GARDANT LES FORMULES
Rows(xlgn).SpecialCells(xlCellTypeConstants, 23).ClearContents
End If
End Sub