Macro Not Running Correct

jtwusmc

New Member
Joined
Jan 8, 2011
Messages
33
I am working with a macro (Excel 2010) to match destination formatting. The data I am working with is coming through in image format and with merged cells when I paste it.

The macro below is supposed to automatically format the data so when I paste using Ctrl + V, it matches destination formatting. Here's the delema, when I copy the date and press Ctrl V, the macro does not work, however when I go in and run the macro manually (go into macros, select "Paste Values" then hit run, it works perfectly. Can someone take a look at this and see where I am going wrong here...

Code:
Sub Auto_Open()
Application.OnKey "^v", "PasteValues"
End Sub
Sub Auto_Close()
Application.OnKey "^v"
End Sub

Module 1
Code:
Public Sub PasteValues() ' Keyboard Shortcut:Ctrl+v
ActiveSheet.PasteSpecial Format:="Unicode Text"
End Sub
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Where do you have the Auto_Open macro located? It should be in a standard module like your PasteValues macro.

The more current method is to use a...
Code:
Private Sub Workbook_Open()
Application.OnKey "^v", "PasteValues"
End Sub
...event macro located in the ThisWorkbook module.
 
Upvote 0
Thanks for your help. Quick questions:
1.) Should the "Sub_auto open" be in the same module as the "PasteValues" module or a 2nd module by itself?
2.) Also, should I leave the "Sub Auto Close" where it is at or do the same as the with the "Sub_Auto Open"?

Where do you have the Auto_Open macro located? It should be in a standard module like your PasteValues macro.

The more current method is to use a...
Code:
Private Sub Workbook_Open()
Application.OnKey "^v", "PasteValues"
End Sub
...event macro located in the ThisWorkbook module.
 
Upvote 0
1.) Should the "Sub_auto open" be in the same module as the "PasteValues" module or a 2nd module by itself?
2.) Also, should I leave the "Sub Auto Close" where it is at or do the same as the with the "Sub_Auto Open"?

1.) Your choice. Excel doesn't care. I probably would put them all in one module.
2.) Sub Auto_Close has to be in a standard module as well. I would put it in the same module as you put Auto_Open, but it doesn't have to be in the same module.

You're welcome. Glad it works for you.
 
Upvote 0
Thanks for your help! I got it to work. Also assigned "Ctrl +V" in the Macro options which made it work even better!
 
Upvote 0

Forum statistics

Threads
1,224,567
Messages
6,179,568
Members
452,926
Latest member
rows and columns

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