PDA

View Full Version : Didn't work my macro to copy&paste only as formulas by default... can you give it a q



gerotutu
04-17-2017, 01:54 PM
Hi! I need your help to check this macro I found in internet to copy and paste without formatting always by default in Excel. I tried it but it made a complete mess. I get always the same problem: whatever is in the clipboard gets stuck there and everytime I click a cell (any) the content is pasted again and again


Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
On Error Resume Next
Target.PasteSpecial xlPasteFormulas
Application.CutCopyMode = True
End Sub


Is it posible to make Ctrl-V only available as formula without any other formatting? I want to keep the excel clean and tidy.

Hope you can help me. Many thanks!
Gerónimo

mdmackillop
04-17-2017, 02:08 PM
I can't replicate your issue but try
Application.CutCopyMode = False

gerotutu
04-17-2017, 02:36 PM
It's the same thing =S

offthelip
04-17-2017, 03:17 PM
Try this in the worksheet change event NOT the selection change:

Private Sub Worksheet_Change(ByVal Target As Range)
On Error Resume Next


Dim lastaction As String
lastaction = Application.CommandBars("Standard").Controls("&Undo").List(1)


If Left(lastaction, 5) = "Paste" Then
Application.Undo
Target.PasteSpecial xlPasteFormulas
Application.CutCopyMode = True
End If


End Sub

gerotutu
04-18-2017, 09:26 AM
Thanks, offhelip!

I couldn't make your code work but I went for the easiest way. Set up Ctr-v (in macro's options) to run the following code:


Sub Pstfrmul()
Selection.PasteSpecial xlPasteFormulas
End Sub


All the best,
Gerónimo