Hello there!
I'm trying to automate a process in Excel 07 using VB.
The problem stems from a copy/paste bug, it appears. Copy and pasting multiple selections using the Copy/Paste command buttons and keyboard shortcuts, using the system clipboard is fine. I always have to go back and delete the selection in the previous workbook/sheet, which is why I'm trying to write a VB, but at least it works.
The copy/paste, even cut/paste, using the Microsoft Clipboard, that holds multiple entries, is the problem. First, cutting leaves the contents as is in Excel, but the real issue is this. When you highlight and copy multiple selections, say rows 1 through 4 and 7 through 10, what actually goes to the clipboard in the pane is all rows 1 through 10! I was hoping this might be a workaround to save a few keystrokes and then make a VB script possibly doable. And no I'm not using the Paste All option in case you're wondering.
Of course the trouble in copying and pasting multiple selections and deleting them BEFORE pasting them to another book sheet or place in the same sheet, in essence a "cut", which is an inherent behind the scene issue with Excel that I somewhat understand.
Doing some research, it appears a VB script will do what I need.
**** All I really need to be able to do is manually select (highlight) multiple rows (say 5 through 8, 12 through 15 and 27 through 34), different every time, and copy them to another book or sheet and at the same time delete the original selected rows, so I don't have to go back and delete them.
Something as simple as below might work, but I'm horrible at setting dynamic or variable code that runs the script only on the data that I've manually selected. I run into this problem with every script I've ever used or written!
This seems pretty close as well: Cut Multiple Selection, Paste Pieces Together and Delete Original Rows
Of course, not wanting to use an input box defeating the purpose.
If anyone can provide some insight that would be wonderful.
Thank you so much,
Mark
I'm trying to automate a process in Excel 07 using VB.
The problem stems from a copy/paste bug, it appears. Copy and pasting multiple selections using the Copy/Paste command buttons and keyboard shortcuts, using the system clipboard is fine. I always have to go back and delete the selection in the previous workbook/sheet, which is why I'm trying to write a VB, but at least it works.
The copy/paste, even cut/paste, using the Microsoft Clipboard, that holds multiple entries, is the problem. First, cutting leaves the contents as is in Excel, but the real issue is this. When you highlight and copy multiple selections, say rows 1 through 4 and 7 through 10, what actually goes to the clipboard in the pane is all rows 1 through 10! I was hoping this might be a workaround to save a few keystrokes and then make a VB script possibly doable. And no I'm not using the Paste All option in case you're wondering.
Of course the trouble in copying and pasting multiple selections and deleting them BEFORE pasting them to another book sheet or place in the same sheet, in essence a "cut", which is an inherent behind the scene issue with Excel that I somewhat understand.
Doing some research, it appears a VB script will do what I need.
**** All I really need to be able to do is manually select (highlight) multiple rows (say 5 through 8, 12 through 15 and 27 through 34), different every time, and copy them to another book or sheet and at the same time delete the original selected rows, so I don't have to go back and delete them.
Something as simple as below might work, but I'm horrible at setting dynamic or variable code that runs the script only on the data that I've manually selected. I run into this problem with every script I've ever used or written!
Code:
Sub DynamicCutPaste()
Range("2:2,4:4,6:6,8:8,11:11").Select
Range("A11").Activate
Selection.Copy
Application.CutCopyMode = False
Selection.Delete Shift:=xlUp
End Sub
This seems pretty close as well: Cut Multiple Selection, Paste Pieces Together and Delete Original Rows
Of course, not wanting to use an input box defeating the purpose.
Code:
Sub uittoets()
Dim rowCount As Integer
Dim i As Integer
Dim nName As Name 'vir #REF delete
Dim rng() As Range
Dim AantalSeleksies As Integer
'get amount of selections
AantalSeleksies = Selection.Areas.Count
Redim rng(1 To AantalSeleksies) As Range 'skep variables
For i = 1 To AantalSeleksies
Set rng(i) = Selection.Areas(i)
ActiveWorkbook.Names.Add Name:="MyRange" & i, RefersTo:=Selection.Areas(i)
rowCount = rowCount + Selection.Areas(i).Rows.Count
Next i
'Select selections
Selection.Copy
Range("a24").PasteSpecial (xlPasteAll)
For i = 1 To AantalSeleksies
Range("myrange" & i).Select
Range("MyRange" & i).EntireRow.Delete
Next i
'Delete #REF names
For Each nName In Names
If InStr(1, nName.RefersTo, "#REF!") > 0 Then
nName.Delete
End If
Next nName
End Sub
If anyone can provide some insight that would be wonderful.
Thank you so much,
Mark