Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default Run a macro before paste

Is it possible to run a macro automatically before every paste? I need to
paste information from another program into a merged cell (I don't like them
either, but I need them for the sheet), and I keep getting the error message
about pasting into different sized sheets.

If I can't do that, can you run a command button on a mouse click while
another cell is active(not sure if that is the right term, what I mean is
when you select a cell and hit F2 to edit the content, it has the flashing
marker)

Thanks,

David
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Run a macro before paste

David,
There's no _BeforePaste event. What you can achieve will depend on how much
control you have and what you are trying to do.

What is the other "application" ?
If it is not Excel, you may be limited to text and the DataObject.

Whilst macros do not run when the user is in Edit Mode (F2), you could maybe
fake something with SendKeys, although using .Characters may also work.

I did notice something, that for me, was a little strange, with the
different results of these 2 quick recorded macros:

Sub PasteToMerge_NotGood()

Range("A1:A4").Select
With Selection
.MergeCells = True
End With

Sheets("Sheet2").Select
Range("C2:E2").Select
With Selection
.MergeCells = True
End With

Sheets("Sheet1").Select
ActiveCell.FormulaR1C1 = "45"
Range("A1:A4").Select
Selection.Copy
Sheets("Sheet2").Select
Range("C2:E2").Select
ActiveSheet.Paste
Range("C8").Select
End Sub

Sub PasteToMerge_Good()

Range("A1:A4").Select
Application.CutCopyMode = False
With Selection
.MergeCells = True
End With
Sheets("Sheet2").Select
'
'This is the only difference
'Creates a merged range same size as the copied range
'But it is not used at all....
'
Range("A1:A4").Select
With Selection
.MergeCells = True
End With
'
Range("C2:E2").Select
With Selection
.MergeCells = True
End With
Sheets("Sheet1").Select
ActiveCell.FormulaR1C1 = "45"
Range("A1:A4").Select
Selection.Copy
Sheets("Sheet2").Select
Range("C2:E2").Select
ActiveSheet.Paste
'See the different result...
Range("C4").Select
End Sub
Maybe someone else can explain the difference in behaviour, depending on if
the destination sheet is the same as the source sheet or not. And the
existence of a similar shaped merged range on the destination

So maybe if you copied to the sheet (in a suitable out of the way place)
first that contains the destination, then copy that and paste to the real
destination, you can achieve your goal.

But anyway, if the above does not give you any ideas, post back with more
details of the aim.

NickHK

"Dave M" wrote in message
...
Is it possible to run a macro automatically before every paste? I need to
paste information from another program into a merged cell (I don't like

them
either, but I need them for the sheet), and I keep getting the error

message
about pasting into different sized sheets.

If I can't do that, can you run a command button on a mouse click while
another cell is active(not sure if that is the right term, what I mean is
when you select a cell and hit F2 to edit the content, it has the flashing
marker)

Thanks,

David



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
copy multiple worksheets of a workbook, and paste onto a Word document ( either create new doc file or paste onto an existing file.) I need this done by VBA, Excel Macro Steven Excel Programming 1 October 17th 05 08:56 AM
Copy and Paste macro needs to paste to a changing cell reference loulou Excel Programming 0 February 24th 05 10:29 AM
Cut and Paste using Macro gives paste special method error Lourens Pentz Excel Programming 3 November 21st 04 10:42 PM
Macro to Paste to specific line, and continue to Paste each time on next row not over tomkarakowski[_2_] Excel Programming 1 May 28th 04 06:50 PM
Macro to Copy/Paste then Paste to Next Line tomkarakowski Excel Programming 1 May 28th 04 01:19 AM


All times are GMT +1. The time now is 10:14 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"