Auto Paste values

Billdub417

New Member
Joined
Nov 5, 2019
Messages
45
Hello,

I use the following code so that when people paste info into this workbook, it only pastes values.

However, this doesn't work when pasting from 1 workbook to another (as paste values is not an option)

Is there a way to still get it to paste the data in?

thanks,

VBA Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)

 Dim UndoString As String, srce As Range
    On Error GoTo err_handler
    UndoString = Application.CommandBars("Standard").Controls("&Undo").List(1)
    If Left(UndoString, 5) <> "Paste" And UndoString <> "Auto Fill" Then
        Exit Sub
    End If
    Application.ScreenUpdating = False
    Application.EnableEvents = False
    Application.Undo
    If UndoString = "Auto Fill" Then
        Set srce = Selection
        srce.Copy
        Target.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
        Application.SendKeys "{ESC}"
        Union(Target, srce).Select
    Else
        Target.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    End If
    Application.ScreenUpdating = True
    Application.EnableEvents = True
    Exit Sub
err_handler:
    Application.ScreenUpdating = True
    Application.EnableEvents = True
End Sub
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
However, this doesn't work when pasting from 1 workbook to another (as paste values is not an option)
Why is pastespecial values not an option?

VBA Code:
Application.SendKeys "{ESC}"
Why are you using SendKeys? if it is just to come out of copy mode use
VBA Code:
Application.CutCopyMode = False
 
Upvote 0
Why is pastespecial values not an option?

VBA Code:
Application.SendKeys "{ESC}"
Why are you using SendKeys? if it is just to come out of copy mode use
VBA Code:
Application.CutCopyMode = False
Hello, not sure why using send keys :)

Just seems to randomly sometimes not let me use paste values?? Could it be an add-in issue?
 
Upvote 0
Could be but more likely that you are activating/selecting the 2nd workbook and taking it out of copy mode.
The basic code is the Test1 macro in Book1 in the link below, the other option is the Test2 macro which doesn't use copy mode.
Open both workbooks in the links below and run the macro's in Book1 (Book2 is just a blank workbook).

 
Upvote 0
Could be but more likely that you are activating/selecting the 2nd workbook and taking it out of copy mode.
The basic code is the Test1 macro in Book1 in the link below, the other option is the Test2 macro which doesn't use copy mode.
Open both workbooks in the links below and run the macro's in Book1 (Book2 is just a blank workbook).

ok, i think ive narrowed it down a bit further... rather than the above code, it seems to be the following that is cancelling copy mode

Is there a way to avoid this, apart from just showing ribbons all the time? (Ribbons dont show in this workbook but would in other workbooks)

VBA Code:
Private Sub Workbook_Deactivate()

Application.ExecuteExcel4Macro "SHOW.TOOLBAR(""Ribbon"",True)"

End Sub
 
Upvote 0
If you use the 2nd code that I posted you aren't using Copy mode so it isn't an issue.
 
Upvote 0
If you use the 2nd code that I posted you aren't using Copy mode so it isn't an issue.
OK yes, so in the situation I am using it, it would be like Book2 copying from book1 (where the user selects book1)

Can your code be amended to this?
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,552
Members
449,088
Latest member
davidcom

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