VBA move selection to different sheet and insert based on selection

MrGeek1

New Member
Joined
Jul 24, 2019
Messages
32
Hi,

I am working on below to move a selection of rows in sheet x given the string "Dead" to a next sheet (sheet y) and subsequently insert the amount of rows selected in that next sheet. Can anyone give an example how to show this in the code?

Many thanks!


Sub Moverow()


Dim i As Long


For i = 2 To 100
If Worksheets("x").Range("B" & i) = "Dead" Then
Range(Range("B" & i), Range("B" & i).End(xlToRight)).Select
Selection.Copy
Worksheets("y").Select
Rows("2:2").Select
Selection.Insert Shift:=xlDown
End If
Next
End Sub
 
Last edited:

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Do you have any data in col A, or is it completely blank?
 
Upvote 0
In that case try
Rich (BB code):
Sub MrGeek1()
   With Sheets("x")
      .Range("B1").AutoFilter 1, "Dead"
      .AutoFilter.Range.Offset(1).EntireRow.Copy Sheets("y").Range("B" & Rows.count).End(xlUp).Offset(1, -1)
      .AutoFilterMode = False
   End With
End Sub
 
Upvote 0
Thanks, that works. As a next step do you also know how the copied selection rows can be erased from sheet x after pasting it in sheet y?
 
Last edited:
Upvote 0
Like
Rich (BB code):
Sub MrGeek1()
   With Sheets("x")
      .Range("B1").AutoFilter 1, "Dead"
      .AutoFilter.Range.Offset(1).EntireRow.Copy Sheets("y").Range("B" & Rows.count).End(xlUp).Offset(1, -1)
      .AutoFilter.Range.Offset(1).EntireRow.Delete
      .AutoFilterMode = False
   End With
End Sub
 
Upvote 0
I notice that my macro button jumps from sheet x to the specified sheet y after pressing the macro button. Do you have any clue why that is? Thanks
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

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