Beste Formleden,
Ik heb een macro waarbij bestaande shapes in een regel verwijderd moeten worden voordat er een nieuwe wordt geplaatst.
Als er een wijziging plaats vind in kolommen "C, E, G" De nieuwe shape wordt wel geplaatst, maar de oude blijven ook staan.
Verder zit in de macro een vertikaal zoek argument, alleen pakt die maar één kleur.
onderstaande macro: zie ook de bijlage.
Alvast bedankt voor jullie reacties
Ik heb een macro waarbij bestaande shapes in een regel verwijderd moeten worden voordat er een nieuwe wordt geplaatst.
Als er een wijziging plaats vind in kolommen "C, E, G" De nieuwe shape wordt wel geplaatst, maar de oude blijven ook staan.
Verder zit in de macro een vertikaal zoek argument, alleen pakt die maar één kleur.
onderstaande macro: zie ook de bijlage.
Alvast bedankt voor jullie reacties
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim ShpNum As String
'Check if E or F date columns and ignore if not
If Intersect(Target, Range("C12:E50", "G12:G50")) Is Nothing Then Exit Sub 'Edit 12 & or 50 if inappropriate
'Check if more than one cell and ignore if yes
If Target.Count > 1 Then Exit Sub
'Otherwise...
r = Target.Row
' ignore if an empty Column C in row
If Cells(r, 7) = "" Then Exit Sub
'otherwise a date has been changed
ShpName = "SHP_" & Cells(r, 7) 'Shape Name
'Delete current shape of that name if it exists
On Error Resume Next
For Each xshape In TagetRow.ShapesRange(Array(ShpName)).Delete
If xshape.TopLeftCell.Row = myRow Then xshape.Delete
Next
'get equal date cells
LftCell = Cells(r, 5) - Cells(10, 5) + 8
RtCell = Cells(r, 6) - Cells(10, 5) + 8
On Error GoTo 0
Select Case Cells(r, 7) = Value
Case Is <> 0
'diamond for Milestone date
Set NewShp = ActiveSheet.Shapes.AddShape(msoShapeDiamond, Cells(r, LftCell).Left, Cells(r, LftCell).Top + 2, Cells(r, LftCell).Width, Cells(r, LftCell).Height - 4)
NewShp.Fill.ForeColor.RGB = FormulaLocal = "VERT.ZOEKEN(range(C12:C50);Blad3!E3:I28;5;onwaar)"
NewShp.Line.ForeColor.RGB = FormulaLocal = "VERT.ZOEKEN(range(C12:C50);Blad3!E3:I28;5;onwaar)"
Case Else
On Error GoTo OnlyONEDate:
'Get date ranges
Set DtRng = Range(Cells(r, LftCell), Cells(r, RtCell))
LftCell = Cells(r, 5) - Cells(10, 5) + 8
RtCell = Cells(r, 6) - Cells(r, 5) + 12
'if number in G then add a rectangle
If Cells(r, 3) = "fase" Then
Set NewShp = ActiveSheet.Shapes.AddShape(msoShapeRectangle, DtRng.Left, DtRng.Top + 5, DtRng.Width, DtRng.Height - 10)
NewShp.Fill.ForeColor.RGB = FormulaLocal = "VERT.ZOEKEN(range(C12:C50);Blad3!E3:I28;5;onwaar)"
NewShp.Line.ForeColor.RGB = FormulaLocal = "VERT.ZOEKEN(range(C12:C50);Blad3!E3:I28;5;onwaar)"
Else
'Otherwise if text in C add arrow bar
Set NewShp = ActiveSheet.Shapes.AddShape(msoShapeLeftRightArrow, DtRng.Left, DtRng.Top + 3, DtRng.Width, DtRng.Height - 6)
NewShp.Fill.ForeColor.RGB = FormulaLocal = "VERT.ZOEKEN(range(C12:C50);Blad3!E3:I28;5;onwaar)"
NewShp.Line.ForeColor.RGB = FormulaLocal = "VERT.ZOEKEN(range(C12:C50);Blad3!E3:I28;5;onwaar)"
End If
End Select
'Name shape as per value
NewShp.Name = ShpName
OnlyONEDate:
On Error GoTo 0
End Sub
Bijlagen
Laatst bewerkt door een moderator: