ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Prevent copy and paste in one column (https://www.excelbanter.com/excel-programming/442208-prevent-copy-paste-one-column.html)

Brian

Prevent copy and paste in one column
 
I am having trouble trying to prevent copying and pasting in one specific
column. The code refers to the specific range, but yet it prevents copying
and pasting on the whole worksheet.

Option Explicit

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Not Intersect(Target, Columns("H:H")) Is Nothing Then
Application.CellDragAndDrop = False
Application.CutCopyMode = False
Else
Application.CellDragAndDrop = True
End If

End Sub

Gord Dibben

Prevent copy and paste in one column
 
Works for me in Excel 2003


Gord Dibben MS Excel MVP

On Fri, 30 Apr 2010 11:42:01 -0700, Brian
wrote:

I am having trouble trying to prevent copying and pasting in one specific
column. The code refers to the specific range, but yet it prevents copying
and pasting on the whole worksheet.

Option Explicit

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Not Intersect(Target, Columns("H:H")) Is Nothing Then
Application.CellDragAndDrop = False
Application.CutCopyMode = False
Else
Application.CellDragAndDrop = True
End If

End Sub



Brian

Prevent copy and paste in one column
 

I was thinking it would for me too.... but in 2007 it is not working. Well
correction, it is working too well, it prevents every column not just H....
any ideas?

"Gord Dibben" wrote:

Works for me in Excel 2003


Gord Dibben MS Excel MVP

On Fri, 30 Apr 2010 11:42:01 -0700, Brian
wrote:

I am having trouble trying to prevent copying and pasting in one specific
column. The code refers to the specific range, but yet it prevents copying
and pasting on the whole worksheet.

Option Explicit

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Not Intersect(Target, Columns("H:H")) Is Nothing Then
Application.CellDragAndDrop = False
Application.CutCopyMode = False
Else
Application.CellDragAndDrop = True
End If

End Sub


.


Gord Dibben

Prevent copy and paste in one column
 
Misread your original.

Thought you just wanted to prevent drag and drop in H

Try this simple revision to prevent pasting into H or drag and drop in H

Will not prevent copying from H

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Column < 8 Then Exit Sub
Application.CellDragAndDrop = False
Application.CutCopyMode = False
End Sub


Gord

On Mon, 3 May 2010 13:46:01 -0700, Brian
wrote:


I was thinking it would for me too.... but in 2007 it is not working. Well
correction, it is working too well, it prevents every column not just H....
any ideas?

"Gord Dibben" wrote:

Works for me in Excel 2003


Gord Dibben MS Excel MVP

On Fri, 30 Apr 2010 11:42:01 -0700, Brian
wrote:

I am having trouble trying to prevent copying and pasting in one specific
column. The code refers to the specific range, but yet it prevents copying
and pasting on the whole worksheet.

Option Explicit

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Not Intersect(Target, Columns("H:H")) Is Nothing Then
Application.CellDragAndDrop = False
Application.CutCopyMode = False
Else
Application.CellDragAndDrop = True
End If

End Sub


.




All times are GMT +1. The time now is 10:06 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com