Need help TWEAKING this code...

Mister H

Well-known Member
Joined
Mar 6, 2002
Messages
1,507
Hi All:

The code below is ALMOST doing what I want but there is one problem with it. Due to my lack of VBA skills I am hoping that someone can tell me what needs to be added or subtracted from the code.

The code changes a Copy/Paste to a Copy/PasteSpecial/Values without the user being made aware of it. This is only suppose to happen on my sheet titled "Meeting Minutes".

Problem: When I Paste onto the sheet "Meeting Minutes" it seems to be working. When I Paste onto any other sheet it works but it pops up another menu when the sheet is not titled Meeting Minutes. The menu is the Paste Menu and it is just asking how I want to Paste.

Can anybody tell me how to get rid of that piece and just have the code do a standard Paste? Hope this makes sense... Here is the code:

Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
 
' this code will undo PASTE and instead do a PASTE SPECIAL VALUES which will
' allow you to retain FORMATS in all of the cells in all of the sheets, but
' will also allow the user to COPY and PASTE data
 
    Dim UndoString As String
    Dim srce As Range
    On Error GoTo err_handler
 
 
  If Target.Parent.Name <> "Meeting Minutes" Then
  Application.CommandBars("Standard").Controls("&Paste").Execute
 
  Else
 
    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
    End If
    
    Application.ScreenUpdating = True
    Application.EnableEvents = True
    Exit Sub
 
err_handler:
    Application.ScreenUpdating = True
    Application.EnableEvents = True
 
End Sub

Can anyone assist in getting this to work WITHOUT popping up the Paste Menu? :confused:

THANKS,
Mark :biggrin:
 
Rich (BB code):
If Target.Parent.Name <> "Meeting Minutes" Then
Application.CommandBars("Standard").Controls("&Paste").Execute
Application.SendKeys ("{Esc}")
....
....
 
Upvote 0
SORRY for not responding sooner but I was away from my computer until now...

THANKS for your reply Mala. I will try out the piece of code you added. :)

Have a GREAT day,
Mark :biggrin:
 
Upvote 0
Rich (BB code):
If Target.Parent.Name <> "Meeting Minutes" Then
Application.CommandBars("Standard").Controls("&Paste").Execute
Application.SendKeys ("{Esc}")
....
....

Mala ,

I saw a link to this post from another question forum and wondered if you could answer this for me. If I use this code, is there a way to make it only target a specific Range of cells in only one worksheet?
 
Upvote 0

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