Is there a way to prevent copying in an excel only for some columns?

0

Is there any way that the values of a column can not be copied in excel?

I tried to make the column not selectable and protected it with a password, but you can still copy the values by selecting the columns on the sides.

I think the solution could be at the VBA code level or from some other excel file processor, like Apache POI.

    
asked by d345k0 22.11.2016 в 19:19
source

1 answer

2

Copying from VBA can be disabled with Application.CutCopyMode .

To allow or not allow it to be copied, we have to change this property every time the current selection changes. In the code of a sheet:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    'especificamos un rango prohibido de ejemplo 
    Dim RangoProhibido As Range
    Set RangoProhibido = Range("A1:C6")

    'Verificar que la selección actual no tenga celdas dentro del rango prohibido (vemos la intersección)
    If (Application.Intersect(Target, RangoProhibido) Is Nothing) Then
        'permite copiar
        Application.CutCopyMode = True
    Else
        'no se puede copiar
        Application.CutCopyMode = False
    End If
End Sub
    
answered by 23.12.2016 в 06:06