I have the following code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim btn As Button
Dim t As Range
Dim i As Integer
i = Target.Row
If Not Intersect(Target, Range("$B10:$B103")) Then
If Target.Value <> "" Then
For Each btn In ActiveSheet.Buttons
If btn.Name = "I" & i Then
btn.Delete
End If
Next btn
Set t = ActiveSheet.Range(Cells(i, 9), Cells(i, 9))
Set btn = ActiveSheet.Buttons.Add(t.Left, t.Top, t.Width, t.Height)
With btn
.OnAction = "imageshow"
.Caption = "View Images"
.Name = "I" & i
End With
Else
For Each btn In ActiveSheet.Buttons
If btn.Name = "I" & i Then
btn.Delete
End If
Next btn
End If
End If
End Sub
When I run it, it works if the value entered into B10:B103 is an Integer number, but if I use text or a Long number a combination of text and numbers (data entered in here will be of this form) then it will not work.