How to Create Floating Button or movable button in excel throung visual basic
First Add Shapes from Insert Tab into worksheet and select shape and remane it.
Here I have inserted two shapes one is Plus Sign and another is cross sign and remane it as insert and "delete"
Now goto worksheet name and right click on it --> view code and follow the below process
First You need to set condition by which shapes or button will be visible
If Not Intersect(Target, Me.ListObjects("Table2").ListColumns(2).DataBodyRange) Is Nothing Then
here if not intersect means --> if you do not select your target cell i.e your target is a range. here my target is 2nd column of Table2, so I used here
Me.ListObjects("Table2").ListColumns(2).DataBodyRange.
If You want to set a range then simply write
Range("B19:D23")
Now write for a shapes or button
With ActiveSheet.Shapes.Range(Array("delete"))
Now set Visible or not
.Visible = True
Now set Position of the shapes
.Left = ActiveCell.Offset(0, 11).Left - 2.Top = ActiveCell.Offset(0, 11).Top
Thats it
VBA codes are follow .................................
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Me.ListObjects("Table2").ListColumns(2).DataBodyRange) Is Nothing Then
With ActiveSheet.Shapes.Range(Array("delete"))
.Visible = True'Change the number of points between the shape and the row numbers
.Left = ActiveCell.Offset(0, 11).Left - 2
.Top = ActiveCell.Offset(0, 11).Top
End With
With ActiveSheet.Shapes.Range(Array("insert"))
.Visible = True
.Left = ActiveCell.Offset(0, -2).Left + 6
.Top = ActiveCell.Offset(0, -2).Top
End With
Else
ActiveSheet.Shapes.Range(Array("delete")).Visible = False
ActiveSheet.Shapes.Range(Array("insert")).Visible = False
End If
End Sub
Briliant idea! Thanks lot, Need more project like this.Thanks again.
ReplyDelete