Cut Rows

liampog

Active Member
Joined
Aug 3, 2010
Messages
308
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi

I have the following code that disables cutting and pasting (so as to avoid formatting being messed up, especially conditional formatting).

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
   
    Select Case Application.CutCopyMode
   
        Case Is = False
       
        Case Is = xlCopy
       
        Case Is = xlCut
       
        Application.CutCopyMode = False
   
    End Select

End Sub

I also have the following code that, if a user copies and attempts to paste, it changes the paste to Paste Special Values (again to avoid formatting being messed up):

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    If Application.CutCopyMode = xlCopy Then
       
        With Application

            .ScreenUpdating = False
           
            .EnableEvents = False
           
            .Undo
       
            Target.PasteSpecial Paste:=xlPasteValues
       
            .EnableEvents = True

            .ScreenUpdating = True
       
        End With
       
    End If

End Sub

However, I don't want the first piece of code to fire if the user is cutting an entire row and inserting the row in a different position. I only want it to fire if the user is attempting to cut a particular range of cells.

Can anyone tell me if it's possible and what modification of the code is required?

Thanks
Liam
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Nevermind, I reworded my Google Search and found this:

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    
    If Not (Selection.Rows.Count = 1 And Selection.Columns.Count = ActiveSheet.Columns.Count) Then
        
        Select Case Application.CutCopyMode
        
            Case Is = False
            
            Case Is = xlCopy
            
            Case Is = xlCut
            
            Application.CutCopyMode = False
        
        End Select
    
    End If

End Sub

Hate it when that happens :)
 
Upvote 0

Forum statistics

Threads
1,215,228
Messages
6,123,747
Members
449,118
Latest member
kingjet

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top