Lovelylou79
New Member
- Joined
- Sep 4, 2017
- Messages
- 37
Hi Excel Community,
Long time code thief, first time poster....
I'm looking for assistance with Cutting, Pasting and Deleting rows from Sheet 1 to Sheet 3 ("#PRU"), based on a list of values from Sheet 2 ("Codes").
I have investigated several codes from this and other forums, however I can not seem to make them fit my exact purposes.
The closest I have come is the following, which bugs out at the "Insert" line;
Sub cutrows()
Sheets.Add After:=Sheets(Sheets.Count)
ActiveSheet.Name = "#PRU"
Dim d As Object, e, rws&, cls&, i&, j&
Set d = CreateObject("scripting.dictionary")
For Each e In Sheets("Codes").Range("A1").CurrentRegion
d(e.Value) = 1
Next e
Sheets("Phish").Activate
rws = Cells.Find("*", After:=[a1], searchorder:=xlByRows, _
searchdirection:=xlPrevious).Row
cls = Cells.Find("*", After:=[a1], searchorder:=xlByColumns, _
searchdirection:=xlPrevious).Column
For i = rws To 1 Step -1
For j = 1 To cls
If d(Range("A1").Resize(rws, cls)(i, j).Value) = 1 Then _
Cells.Rows(i).Cut Sheets("#PRU").Range("1:1").EntireRow.Insert: Exit For
Next j, i
End Sub
This code was originally intended for deleting the rows, I have tried to manipulate it to cut and paste. Ideally the row would be deleted once the cut/paste function is completed.
Any assistance would be greatly appreciated.
Long time code thief, first time poster....
I'm looking for assistance with Cutting, Pasting and Deleting rows from Sheet 1 to Sheet 3 ("#PRU"), based on a list of values from Sheet 2 ("Codes").
I have investigated several codes from this and other forums, however I can not seem to make them fit my exact purposes.
The closest I have come is the following, which bugs out at the "Insert" line;
Sub cutrows()
Sheets.Add After:=Sheets(Sheets.Count)
ActiveSheet.Name = "#PRU"
Dim d As Object, e, rws&, cls&, i&, j&
Set d = CreateObject("scripting.dictionary")
For Each e In Sheets("Codes").Range("A1").CurrentRegion
d(e.Value) = 1
Next e
Sheets("Phish").Activate
rws = Cells.Find("*", After:=[a1], searchorder:=xlByRows, _
searchdirection:=xlPrevious).Row
cls = Cells.Find("*", After:=[a1], searchorder:=xlByColumns, _
searchdirection:=xlPrevious).Column
For i = rws To 1 Step -1
For j = 1 To cls
If d(Range("A1").Resize(rws, cls)(i, j).Value) = 1 Then _
Cells.Rows(i).Cut Sheets("#PRU").Range("1:1").EntireRow.Insert: Exit For
Next j, i
End Sub
This code was originally intended for deleting the rows, I have tried to manipulate it to cut and paste. Ideally the row would be deleted once the cut/paste function is completed.
Any assistance would be greatly appreciated.