Float button on current row

vabtroni

New Member
Joined
Aug 1, 2017
Messages
41
Office Version
  1. 365
Platform
  1. Windows
Greetings everyone.

I have a button called "but_ENV_AVARIAS" wich runs a macro, and I need it to float on the current selected row near column I (with a fixed horizontal position), except if:
- current row is above row 8
- current row is below row 30007
...meaning, if selected row is not between rows 8 and 30007, I would like that button to become invisible.

Is there any chance I could put it on VBA?

Best regards,
Vasco.
 
So you do not have to change all the button names in this script just change the name in this script highlighted in red.

Try this:
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("A:K")) Is Nothing Then
Dim ans As String
ans = "[COLOR=#ff0000]but_ENV_AVARIAS[/COLOR]"
If Target.Cells.Count > 1 Then Exit Sub
If ActiveCell.Row < 8 Or ActiveCell.Row > 30007 Then
ActiveSheet.Shapes.Range(ans).Visible = False
Else
ActiveSheet.Shapes.Range(ans).Visible = True
End If
ActiveSheet.Shapes.Range(ans).Top = ActiveCell.Top
ActiveSheet.Shapes.Range(ans).Left = Cells(1, "N").Left
End If
End Sub
 
Upvote 0

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
You said "A:K" and then next to "I" which is inside "A:K" so I set it to "N" change "N" marked in red to what you want.

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("A:K")) Is Nothing Then
Dim ans As String
ans = "[COLOR=#ff0000]but_ENV_AVARIAS[/COLOR]"
If Target.Cells.Count > 1 Then Exit Sub
If ActiveCell.Row < 8 Or ActiveCell.Row > 30007 Then
ActiveSheet.Shapes.Range(ans).Visible = False
Else
ActiveSheet.Shapes.Range(ans).Visible = True
End If
ActiveSheet.Shapes.Range(ans).Top = ActiveCell.Top
ActiveSheet.Shapes.Range(ans).Left = Cells(1, "[COLOR=#ff0000]N[/COLOR]").Left
End If
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,566
Messages
6,125,593
Members
449,237
Latest member
Chase S

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top