HI Guys
Could someone please help me with this problem.
This macro inserts a button and names it corresponding to the cell row the value is entered . My issue is when the value is deleted from that row i want the button to be deleted also.
When i change this macro to hide and unhide the button (that has been created already before the macro runs) rather than create a new button inside the macro it works perfect. The problem seems to be creating the button inside the macro.
Thanks
Private Sub Worksheet_Change(ByVal Target As Range)
d1 = "D-01"
d2 = "D-02"
Dim u As String
u = Cells(Target.Row, 2)
If Not Intersect(Target, Range("H47:H96")) Is Nothing Then
If UCase(Cells(Target.Row, 8)) = d1 Or _
UCase(Cells(Target.Row, 8)) = d2 _
Then _
'ActiveSheet.Shapes.Range(Array(u)).Visible = msoTrue
ActiveSheet.Shapes.AddShape(msoShapeRoundedRectangle, 390, _
662.4, 45, 14.4).Select
Selection.ShapeRange.ThreeD.BevelTopType = msoBevelNone
Selection.ShapeRange.Shadow.Visible = msoFalse
Selection.ShapeRange.Name = u
With Selection.ShapeRange.Fill
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorAccent1
.ForeColor.TintAndShade = 0
.ForeColor.Brightness = -0.25
.Transparency = 0.2900000215
.Solid
End With
Selection.ShapeRange.TextFrame2.TextRange.Font.size = 10
Selection.ShapeRange(1).TextFrame2.TextRange.Characters.Text = "Modify"
With Selection.ShapeRange(1).TextFrame2.TextRange.Characters(1, 6).Font
.NameComplexScript = "+mn-cs"
.NameFarEast = "+mn-ea"
.Fill.Visible = msoTrue
.Fill.ForeColor.ObjectThemeColor = msoThemeColorLight1
.Fill.ForeColor.TintAndShade = 0
.Fill.ForeColor.Brightness = 0
.Fill.Transparency = 0
.Fill.Solid
.size = 10
.Name = "+mn-lt"
End With
Range("A1").Select
End If
End If
If Not Intersect(Target, Range("H47:H96")) Is Nothing Then
If UCase(Cells(Target.Row, 8)) = "" _
Then _
ActiveSheet.Shapes.Range(Array(u)).Select
Selection.Delete
End If
End If
Stop
End Sub
Could someone please help me with this problem.
This macro inserts a button and names it corresponding to the cell row the value is entered . My issue is when the value is deleted from that row i want the button to be deleted also.
When i change this macro to hide and unhide the button (that has been created already before the macro runs) rather than create a new button inside the macro it works perfect. The problem seems to be creating the button inside the macro.
Thanks
Private Sub Worksheet_Change(ByVal Target As Range)
d1 = "D-01"
d2 = "D-02"
Dim u As String
u = Cells(Target.Row, 2)
If Not Intersect(Target, Range("H47:H96")) Is Nothing Then
If UCase(Cells(Target.Row, 8)) = d1 Or _
UCase(Cells(Target.Row, 8)) = d2 _
Then _
'ActiveSheet.Shapes.Range(Array(u)).Visible = msoTrue
ActiveSheet.Shapes.AddShape(msoShapeRoundedRectangle, 390, _
662.4, 45, 14.4).Select
Selection.ShapeRange.ThreeD.BevelTopType = msoBevelNone
Selection.ShapeRange.Shadow.Visible = msoFalse
Selection.ShapeRange.Name = u
With Selection.ShapeRange.Fill
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorAccent1
.ForeColor.TintAndShade = 0
.ForeColor.Brightness = -0.25
.Transparency = 0.2900000215
.Solid
End With
Selection.ShapeRange.TextFrame2.TextRange.Font.size = 10
Selection.ShapeRange(1).TextFrame2.TextRange.Characters.Text = "Modify"
With Selection.ShapeRange(1).TextFrame2.TextRange.Characters(1, 6).Font
.NameComplexScript = "+mn-cs"
.NameFarEast = "+mn-ea"
.Fill.Visible = msoTrue
.Fill.ForeColor.ObjectThemeColor = msoThemeColorLight1
.Fill.ForeColor.TintAndShade = 0
.Fill.ForeColor.Brightness = 0
.Fill.Transparency = 0
.Fill.Solid
.size = 10
.Name = "+mn-lt"
End With
Range("A1").Select
End If
End If
If Not Intersect(Target, Range("H47:H96")) Is Nothing Then
If UCase(Cells(Target.Row, 8)) = "" _
Then _
ActiveSheet.Shapes.Range(Array(u)).Select
Selection.Delete
End If
End If
Stop
End Sub