Results 1 to 3 of 3
  1. #1

    Thread Starter
    New Member
    Join Date
    May 2012

    Resolved [RESOLVED] floating command button within a range

    Hi everyone,

    I found a way of adding a floating command button through googling, but I would like to only assign this to the first 7 columns of the worksheets and have the command button always to the right of the 7th column.
    Here is the code I have for now which will put the command button to the right of the active cell. It does not seem to work when I put range into the code.
    I am trying to make the command button always appear at the right hand side of the 7th column when the active cell is within the first 7 columns otherwise it will not show up or it would not change its position.

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        ActiveSheet.Shapes(1).Left = ActiveCell.Left + ActiveCell.Width + 3
        ActiveSheet.Shapes(1).Top = ActiveCell.Top
    End Sub
    I am not sure if this is achievable.
    Thank you.

  2. #2
    Join Date
    Oct 2008
    Midwest Region, United States

    Re: floating command button within a range

    An example:

    Sub Macro1()
        Dim shapeLeft As Integer
        Dim i As Integer
        For i = 1 To 7
            shapeLeft = shapeLeft + Columns(i).Width
        Next i
        ActiveSheet.Shapes(1).Left = shapeLeft
    End Sub

  3. #3
    Join Date
    Dec 2004

    Re: floating command button within a range

    vb Code:
    1. if target.column > 8 then
    2.     ' your code
    3. end if
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts


Click Here to Expand Forum to Full Width

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.