I am searching a VBA code which will return the copied range(Dashline border /Marching ant rang). Seeking the kind help from excel experts.
Background of the problem:
Let's say I copy a range. In Excel, Copied Range will be highlighted with a dashed border. Then I just select another cell. Now I will run a macro. After running the macro, in messageBox, I want to see the cell address of the Copied range (not the cell address of the selection).
Example:
- Lets say I Copied Range("$A$1:$A$5") and select B1Cell. When I will run the macro, messageBox will show $A$1:$A$5.
- Or Lets say I Copied Range("$C$5:$E$10") and select B1Cell. When I run the macro, messageBox will show $C$5:$E$10.
Solution looking for:
1. If only contiguous cell range is copied, then VBA code will return on ONE copied cells address.
2. If multi-range are copied, then there will be 02 result. One is for Union of all individual separate range and another one will return one cell address from left top corner to bottom right corner.
I am not very much an expert in windows API. So I really need your kind help.
Just want to mention what I have found. So far, I have found 03 ways:-
1. Paste as link method: To me, this is not the right method. This is a trick. Also It obviously still has some holes. Good thing that this returns multiple selection copied range. But This is a very slow method when a full column is copied. (Attachment)
2. Worksheet_SelectionChange method: This method is not workable for me. Because my macro will be used in any sheet (Like as excel add-in).
3. Window API (or something else) method: With adding additional/3rd party libraries, I have seen many ways. But I could figure out how to use it.
Get the copied range address.xlsm
Bookmarks