I have a workbook from which I need to copy & paste multiple rows into a non-Excel program. If I Ctrl+Click the rows I want and then copy them, it copies everything between the first and last row, not just the highlighted row. Is there any way to disable this "feature"?
I wrote a macro that will copy only the highlighted rows to the clipboard and set Ctrl-C as the shortcut key for it. The problem is that some people prefer to right click and select copy (or click the copy icon from the ribbon) rather than pressing Ctrl-C. Is there any way to trigger the macro any time a copy takes place, regardless of how it is triggered?
Also, for the benefit of anyone who stumbles across this thread looking for a way to copy only the highlighted lines, I'll include the macro I'm using. There's probably a more elegant way to accomplish it, but this works:
Sub CopyBrokenRangeToClipboard()
Dim rng As Range
Dim DataObj As New MSForms.DataObject
Dim S As String
Dim X As Integer
Application.CutCopyMode = False
For Each rng In Selection.Rows
X = rng.Row
S = S & CStr(ActiveSheet.Cells(X, 1).Value) & vbTab
S = S & CStr(ActiveSheet.Cells(X, 2).Value) & vbTab
S = S & CStr(ActiveSheet.Cells(X, 3).Value) & vbTab
S = S & CStr(ActiveSheet.Cells(X, 4).Value) & vbTab
S = S & CStr(ActiveSheet.Cells(X, 5).Value) & vbTab
S = S & CStr(ActiveSheet.Cells(X, 6).Value) & vbTab
S = S & CStr(ActiveSheet.Cells(X, 7).Value) & vbTab
S = S & CStr(ActiveSheet.Cells(X, 8).Value) & vbTab
S = S & CStr(ActiveSheet.Cells(X, 9).Value) & vbTab
S = S & vbNewLine
Next rng
DataObj.SetText S
DataObj.PutInClipboard
End Sub
(Looking at it now, I realize I could have have cut out several lines by wrapping the repeated S= in another For loop. I'm sure there are other improvements that could be made as well, but it's a moot point if it can't be triggered via RightClick-Copy and the Copy icon.)
Bookmarks