Consulting

Results 1 to 5 of 5

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

  1. #1
    VBAX Newbie
    Joined
    Apr 2017
    Posts
    3
    Location

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

    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

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    I can't replicate your issue but try
    Application.CutCopyMode = False
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    VBAX Newbie
    Joined
    Apr 2017
    Posts
    3
    Location
    It's the same thing =S

  4. #4
    VBAX Expert
    Joined
    May 2016
    Posts
    604
    Location
    Try this in the worksheet change event NOT the selection change:

    [VBA]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


    [/vba]

  5. #5
    VBAX Newbie
    Joined
    Apr 2017
    Posts
    3
    Location
    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

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •