iabbott
06-28-2010, 09:57 AM
I am looking for a way to stop users using the cut operation, and if a user does try to cut data, to instead have a macro that will copy/paste the data then clear the initial cell contents.
I want this as the users of the spreadsheet are only entering data, but this data is collected by another sheet in the workbook which gets screwed up if cells are cut and pasted.
I ideally don't want to completely disable the cut operation, just change it as described above.
I have currently got this code in the "ThisWorkbook" object:
Private Sub Workbook_Open()
Cell1 = ActiveCell.AddressLocal
End Sub
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
If Application.CutCopyMode = xlCut Then
Range(Cell1).Copy
Else
Cell1 = ActiveCell.AddressLocal
End If
End Sub
'Cell1' is the range which has been cut, or the currently active cell if nothing has been cut
The Workbook_Open code is in case the user doesn't move the cursor before cutting.
As you can see I have got code to check if the CutCopyMode is set to Cut once the user moves the cursor (which they will have to do in order to paste elsewhere) and then changes the mode to copy rather than cut, but this is as far as I can get..
I don't know of a way to tell if the user has pasted the data to a cell, the only way I can think of is to get then next cell they select, store it's value, then on the next move, compare that cells' value with 'Cell1''s value, if they match, clear the contents of 'Cell1', but this is quite messy, as the user will be expecting the original data to disappear when they press paste, but it will only go once they move again.
Therefore I am looking for a better, neater way of doing it.
Thanks in advance for any help.
I want this as the users of the spreadsheet are only entering data, but this data is collected by another sheet in the workbook which gets screwed up if cells are cut and pasted.
I ideally don't want to completely disable the cut operation, just change it as described above.
I have currently got this code in the "ThisWorkbook" object:
Private Sub Workbook_Open()
Cell1 = ActiveCell.AddressLocal
End Sub
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
If Application.CutCopyMode = xlCut Then
Range(Cell1).Copy
Else
Cell1 = ActiveCell.AddressLocal
End If
End Sub
'Cell1' is the range which has been cut, or the currently active cell if nothing has been cut
The Workbook_Open code is in case the user doesn't move the cursor before cutting.
As you can see I have got code to check if the CutCopyMode is set to Cut once the user moves the cursor (which they will have to do in order to paste elsewhere) and then changes the mode to copy rather than cut, but this is as far as I can get..
I don't know of a way to tell if the user has pasted the data to a cell, the only way I can think of is to get then next cell they select, store it's value, then on the next move, compare that cells' value with 'Cell1''s value, if they match, clear the contents of 'Cell1', but this is quite messy, as the user will be expecting the original data to disappear when they press paste, but it will only go once they move again.
Therefore I am looking for a better, neater way of doing it.
Thanks in advance for any help.