Created
April 15, 2013 13:26
-
-
Save AlunHewinson/5388042 to your computer and use it in GitHub Desktop.
A shortcut key to paste special value in Excel is incredibly useful to me. Sometimes, though, the code would break if I was pasting from text copied from a website. This tries the second type of paste if the first errors. You just need to assign a shortcut key to the macro; I use ctrl-m.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub PasteValues() | |
On Error GoTo txt | |
Selection.PasteSpecial Paste:=xlPasteValues | |
Exit Sub | |
txt: | |
If ActiveCell.MergeCells Then | |
Application.DisplayAlerts = True | |
Dim DObj As MSForms.DataObject | |
Dim s As String | |
Set DObj = New MSForms.DataObject | |
DObj.GetFromClipboard | |
s = DObj.GetText | |
ActiveCell.Formula = s | |
Else | |
Application.DisplayAlerts = False | |
ActiveSheet.PasteSpecial Format:="Text", Link:=False, DisplayAsIcon:=False | |
End If | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A shortcut key to paste special value in Excel is incredibly useful to me. Sometimes, though, the code would break if I was pasting from text copied from a website. This tries the second type of paste if the first errors. You just need to assign a shortcut key to the macro; I use ctrl-m.