Floating Command Button on Excel Sheet within the Active Window

arijitirf

Board Regular
Joined
Aug 11, 2016
Messages
98
Office Version
  1. 2016
Platform
  1. Windows
Hello!!
I need a Floating Command Button on the Excel Worksheet which can automatically moves around within the area of Active Window (if the Command Button is positioned on the Top Right Corner and as soon as I move the Cursor to the active cell in the Top Right corner then the Command Button should move to its Left and the Command Button would not leave the Active Window Area.)

I'm using below Codes to get the position of the Command Button in the Top Right Corner but issue with this code is it blocks view of the Cell on the Top Right Corner.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
On Error Resume Next
With Me.CommandButton1
.Top = ActiveWindow.VisibleRange.Top 'ActiveCell.Top + ActiveWindow.VisibleRange '+ .Width
.Left = ActiveWindow.VisibleRange.Width - 93
End With
End Sub


I want it to be moved automatically to its left when the cursor position is on the top Right Cell, just beneath the Command Button.

Requesting help

Thanks in advance.
 
For bottom-left, the code changes to this:
VBA Code:
Option Explicit

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim bottomLeftCell As Range
    Dim vr As Range
    Set vr = ActiveWindow.VisibleRange
    Set bottomLeftCell = ActiveSheet.Cells(vr.Rows.Count + vr.Cells(1, 1).Row - 3, vr.Cells(1, 1).Column)
    With Me.CommandButton1
        .Left = bottomLeftCell.Left
        .Top = bottomLeftCell.Top
        If ActiveCell.Left >= .Left Then
            If ActiveCell.Top >= (.Top - .Height) Then
                .Left = .Left + .Width
            End If
        End If
    End With
End Sub
Excellent!! Working as per my requirement. Thank you so much for giving time to me.

Regards,

Arijit Ghosh
 
Upvote 0

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

Forum statistics

Threads
1,214,987
Messages
6,122,613
Members
449,090
Latest member
vivek chauhan

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