|
-
May 7th, 2012, 04:36 PM
#1
Thread Starter
New Member
[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.
Code:
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.
-
May 7th, 2012, 06:37 PM
#2
Re: floating command button within a range
An example:
Code:
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
-
May 8th, 2012, 04:50 AM
#3
Re: floating command button within a range
vb Code:
if target.column > 8 then ' your code 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
pete
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|