PDA

View Full Version : Solved: button that follows by click unables copying



Ger
09-19-2011, 03:52 AM
Hi,

with the help of this forum i've a macro that makes the commandbutton follow by click, but now i cann't copy and paste because the button cancels the selection.

Who has a solution that makes both possibly ( button that follows and copying)

Ger

GTO
09-19-2011, 04:08 AM
Private Sub CommandButton1_Click()
controle
End Sub

I am afraid that this procedure is nowhere to be found in the attachment.

Ger
09-19-2011, 04:31 AM
Indeed i didn't submit procedure Controle. Because it is not necessary.
If i select a range for example A4 to a26 and try to copy this to H4 to H 26 the selection is gone as soon as i click on H4.

Ger

Aussiebear
09-19-2011, 05:42 AM
Hi Ger, when looking at your workbook, I too can copy but not paste the cells because the Paste and PasteSpecial options are greyed out.

Ger
09-19-2011, 05:54 AM
Aussiebear,
that is my problem. If I delete the code that makes the commandbutton follow the cursor than i can copy and paste, so the code must make it impossible to copy and paste.

Ger

Aussiebear
09-19-2011, 06:19 AM
Why not make the button fixed in position, but make the sheet scroll?

Ger
09-19-2011, 06:40 AM
Because of the structure of the sheet i prefer a floating commandbutton.

Ger

Aflatoon
09-19-2011, 06:50 AM
You might try changing the worksheet code to:


Private Declare Function CloseClipboard Lib "User32" () As Long
Private Declare Function OpenClipboard Lib "User32" (ByVal hWnd As Long) As Long

Private Sub CommandButton1_Click()
controle
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim blnClip As Boolean
Dim Shp As Object
If Application.CutCopyMode <> False Then
blnClip = True
OpenClipboard 0&
End If
Set Shp = ActiveSheet.CommandButton1

With Shp
.Left = ActiveCell.Left
.Top = ActiveWindow.Top
.Width = 90 ' or a desired fixed width
.Height = 45 ' or a desired fixed height
End With

Shp.Object.TakeFocusOnClick = False 'Optional. keeps focus on the selected cell instead of the button
If blnClip Then CloseClipboard
End Sub

Ger
09-19-2011, 11:32 PM
Thx Aflatoon,

this works fine.

Ger