Losing Validation and Conditional Formatting on paste

rhmkrmi

Active Member
Joined
Aug 17, 2012
Messages
348
Office Version
  1. 365
Platform
  1. Windows
Hello,

Is there a way to avoid losing conditional formatting and data validation when pasting data in the cells?

Thank you.
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Hi, If you are talking about the condition destination cell, then pasting as value of the data will not impact conditional formatting. If you are talking about the source cell, depending on the type of conditional formatting like formula can still work in the expected way depending on the way the formula is used. Data Validation will also get copied from source.

Example: I used a conditional formatting formula on column J (=$J2="Text A"), when I pasted it Cell P3 it still looked as $J3 and gave right format.

If you have any specific case where it is not working please let me know, can look at that.

Thanks
 
Upvote 0
This is going to be used by multiple users and I cannot control how they paste the data.
If you paste data, for example from a word document, it will clear the conditional formatting and the data validation in the cell.

I need to make sure that when users paste data in the cells, the conditional formatting and the data validation stay!

Thanks.
 
Upvote 0
You could try some small vba code to prevent pasting onto target cells as follows:

Place this in the worksheet module and change cell A1 to suit:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    Dim sUndoList As String

    On Error Resume Next
    If Not Intersect(Target, Range("A1")) Is Nothing Then
        sUndoList = CommandBars.FindControl(ID:=128).List(1)
        If Left(sUndoList, 5) = "Paste" Or sUndoList = "Auto Fill" Or sUndoList = "Drag and Drop" Then
            Application.EnableEvents = False
            Application.Undo
            Application.OnUndo "", ""
            Application.EnableEvents = True
        End If
    End If

End Sub

EDIT:
Note this code is language dependent.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,191
Members
453,021
Latest member
pingpong7117

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