J'ai un code qui fonctionne quand une cellule change dans la colonne B.Ajout d'une bordure à la dernière ligne utilisée via VBA?
code:
'Insert Depot Memo Data for user
Dim oCell As Range, targetCell As Range
Dim ws2 As Worksheet
If Not Intersect(Target, Range("B:B")) Is Nothing Then ' <-- run this code only if a value in column B has changed
If ActiveCell.Value <> "" Then
If Not GetWb("Depot Memo", ws2) Then Exit Sub
With ws2
For Each targetCell In Target
Set oCell = .Range("J1", .Cells(.Rows.Count, "J").End(xlUp)).Find(What:=targetCell.Value, LookIn:=xlValues, LookAt:=xlWhole)
If ActiveCell.Value <> "" Then
If Not oCell Is Nothing Then
Application.EnableEvents = False
'Set Format of cell
targetCell.ClearFormats
targetCell.Font.Name = "Arial"
targetCell.Font.Size = "10"
targetCell.Font.Color = RGB(128, 128, 128)
targetCell.HorizontalAlignment = xlCenter
targetCell.VerticalAlignment = xlCenter
targetCell.Borders(xlEdgeBottom).LineStyle = xlContinuous
targetCell.Borders(xlEdgeTop).LineStyle = xlContinuous
targetCell.Borders.Color = RGB(166, 166, 166)
targetCell.Borders.Weight = xlThin
targetCell.Offset(0, -1).Value = Now()
targetCell.Offset(0, 1).Value = oCell.Offset(0, 1)
targetCell.Offset(0, 2).Value = oCell.Offset(0, -2)
targetCell.Offset(0, 3).Value = oCell.Offset(0, -7)
With Range("A9:P1048576")
.FormatConditions.Delete
.FormatConditions.Add Type:=xlExpression, Formula1:="=ROW(B9)=ROW(OFFSET($B$9,COUNTA($B:$B)-2,0))"
With .FormatConditions(1).Borders
.LineStyle = xlContinuous
.Color = vbRed
.Weight = xlThin
End With
End With
Application.EnableEvents = True
End If
End If
Next
End With
End If
End If
La plupart du temps le code fonctionne très bien. Sauf que je veux ajouter une mise en forme conditionnelle à une plage lorsque la cellule a changé.
Cela fonctionne également et ajoute une bordure rouge autour de la prochaine disponible (ligne vide). Cependant, je ne veux pas de bordure rouge autour de la ligne entière. Je veux juste des bordures supérieures et inférieures.
donc je suis en train de le faire:
With .FormatConditions(1).Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Color = vbRed
.Weight = xlThin
End With
Mais mon code cesse de fonctionner et je reçois cette erreur
S'il vous plaît quelqu'un peut me montrer où je me trompe?
merci, mais n'a pas résolu ce – user7415328