Force Paste Special Values

hatman

Well-known Member
Joined
Apr 8, 2005
Messages
2,664
HAH... I think i have asked more questions today than in all the time since I became a member... I guess that means I'm pushing the envelope.

Anywho. I have a workbook where I want to retain FORMATS in all of my cells in all of my sheets, but allow the user to enter data. So I got this code to undo PASTE and instead do a PASTE SPECIAL VALUES:

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

    Dim UndoString As String

    On Error GoTo err_handler

    UndoString = Application.CommandBars("Standard").Controls("&Undo").List(1)
    If Left(UndoString, 5) = "Paste" Then 'Only allow Paste Special|Values
            Application.ScreenUpdating = False
            Application.Undo
            Target.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                    :=False, Transpose:=False
            Application.ScreenUpdating = True
    End If

    Exit Sub

err_handler:

End Sub

Only I had a co-worker submarine this code by simply entering some data, then dragging to fill across. All my formats went south. Any way to fix that?
 
Just wondering if I'm doing something incorrect.. I'm very inexperienced with VBA.

We simply copy the code and paste it in the 'ThisWorkbook' file within the Microsoft Excel Objects folder..? Besides saving this & the workbook as a macro-enabled Excel, what am I missing?

Thanks in advance!

Nevermind! It was an issue with my formatting.. Thanks for the code!
 
Upvote 0

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Nevermind! It was an issue with my formatting.. Thanks for the code!

Hi everyone, I can't make it work for me. I'm doing the exactly same things that describe @Bagel_Mon. Is it actually working with the ctrl+c and ctrl+v shortucts? Sorry if my english is not properly but I'm an Argentinian. Regards, Niko.
 
Upvote 0
Well, I disabled the OnError step, so I could found the error.
For discards some incompatibilitys with my actual project I made a new .xlsm workbook and paste the shared code in the ThisWorbook objet.
1583379872871.png
 
Upvote 0
Sorry for the multiples posts, may could be a Language issue? I'm using the Spanisn version.
1583380670198.png
 
Upvote 0
CONFIRMED, it was a excel language issue! I changed it to english and it works properly.
Is there a way to make the code multi-languages?
Sorry for the multiples posts, at least these may help to someone like me...
1583380887901.png
 
Upvote 0
Is there a way to read, accord to the language selected, the "Auto Fill" , "Paste" and "Undo" strings? because if that is possible, may be the way to make it universal.
Please I will aprecciate if you tell me that, thanks for the code.
If it is not possible, may be I search what languages codes are for english and spanish and entApplication.CommandBars("Standard").Controlser a conditional at beggining with the corresponds translations.

YES IT IS THERE A WAY.

VBA Code:
[/B]
    Undo = Application.CommandBars.FindControl(ID:=128).Caption
    
    Paste = Right(Application.CommandBars.FindControl(ID:=6002).Caption, _
                    Len(Application.CommandBars.FindControl(ID:=6002).Caption) - 1)
                
    AutoFill = Application.CommandBars.FindControl(ID:=24836).Caption
[B]


Thanks for all, Niko.
 

Attachments

  • 1583381871491.png
    1583381871491.png
    7.7 KB · Views: 19
Upvote 0

Forum statistics

Threads
1,215,482
Messages
6,125,061
Members
449,206
Latest member
Healthydogs

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