Force Paste Special Values

blk

Board Regular
Joined
May 27, 2003
Messages
61
I have a template that other users will need to paste data in to certain cells. The user is supposed to paste the values only.

If the user just uses Paste, instead of Paste Special Values, I want excel to force a paste special values, as I want the formatting to remain the same. This can apply for the entire sheet, not just a specific range of cells.

I'm not sure if this can be done, but I thought I'd give it a go.
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Jaafar, this is extremely helpful thank you for sharing.

Unfortunately for me it did not work: I pasted this into the standard and worksheet modules precisely as per your instructions. Any further guidance you can provide would be most appreciated

Hi TommyGun and Blk,

The code posted is great however it only works for copying but NOT moving data.

So if the User makes a Cut /Paste, the data is pasted together with all the Formatting !

To achieve the same result with Cut & Paste, place the first code below in the WorkSheet Module and the Second one in a Standard Module :


1st Part Of Code:


Private Sub Worksheet_Activate()
Customise_CutCopyPaste
End Sub

Private Sub Worksheet_Deactivate()
Restore_CutCopyPaste
End Sub

Public Sub Customise_CutCopyPaste()
With Application
.OnKey "^x", "CutSource"
.OnKey "^v", "PasteTarget"
End With

With CommandBars("Edit")
.Controls("Paste").OnAction = "PasteTarget"
.Controls("Paste Special...").OnAction = "PasteTarget"
.Controls("Cut").OnAction = "CutSource"
End With
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Customise_CutCopyPaste
End Sub

Public Sub Restore_CutCopyPaste()
With Application
.OnKey "^x"
.OnKey "^v"
End With

With CommandBars("Edit")
.Controls("Paste").OnAction = ""
.Controls("Paste Special...").OnAction = ""
.Controls("Cut").OnAction = ""
End With
End Sub



2nd Part Of Code :


Public CutMode As Boolean
Public SourceRange As Range

Public Sub CutSource()
CutMode = True
ActiveCell.Copy
Set SourceRange = ActiveCell
End Sub

Public Sub PasteTarget()
If Application.CutCopyMode = xlCopy And CutMode = True Then
ActiveCell.PasteSpecial xlPasteValues
SourceRange.Clear
CutMode = False
Else
ActiveCell.PasteSpecial xlPasteValues
End If
End Sub




I must admit the codes seem a bit sloppy to me. I hope someone has a simpler solution !


Regards.
 
Upvote 0
Jaafar, this is extremely helpful thank you for sharing.

Unfortunately for me it did not work: I pasted this into the standard and worksheet modules precisely as per your instructions. Any further guidance you can provide would be most appreciated

That code works only in Office 2003 and earlier editions.

For excel 2007 or later , use RibbonX http://www.rondebruin.nl/tips.htm
 
Upvote 0

Forum statistics

Threads
1,223,723
Messages
6,174,122
Members
452,545
Latest member
boybenqn

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