Need help with a Search - Cut - Paste in differnt worksheet

Vman34

New Member
Joined
Apr 12, 2011
Messages
2
Hello, I am relatively new to VBA. I'm trying to build a command button that will allow me sort and move my data quickly. I get about 1000 lines of data daily and I would love to automate this process with a VBA loop. I currently have a workbook with about 8 worksheets, the 2 i'm concerend about are "Data" and "RPM Dept". I'm trying to write a code that will look at the "Data" worksheet in cols "I" & "P". IF col "I" = "R" and col "P" = "RPM Operations" I want to cut the entire row and paist it to sheet "RPM Dept" starting at row 50 or the next avalable row. Then I want it to go back to "Data" and loop until it has checked all of the data. so far I've been able to write a code that works but only pulls one at a time, and only for the critieria of col "P" = "RPM Operations". Any help or suggestions would be greatly appreciated! below is the code i have worked out so far:

Private Sub CommandButton1_Click()
Dim Cell As Range
Dim DstWks As Worksheet
Dim LSearchRow As Integer
Dim LCopyToRow As Integer
Dim LSearchValue As String
Dim MatchCell As Range
Dim R As Long
Dim RngEnd As Range
Dim SrcWks As Worksheet
Dim LCutandPasteToRow As Integer
Dim Addx As String

Set DstWks = Worksheets("RPM Dept")
Set SrcWks = Worksheets("Data")

LSearchValue = "RPM Operations"


'Start search in row 5
LSearchRow = 2
Set RngEnd = DstWks.Cells(Rows.Count, "A").End(xlUp)
LSearchRow = IIf(RngEnd.Row < LSearchRow, LSearchRow, RngEnd.Row + 1)
'Start copying data to row 2 in Sheet2 (row counter variable)
LCutandPasteToRow = 50
Set MatchCell = SrcWks.Cells.Find(LSearchValue, , xlValues, xlWhole, xlByRows, xlNext, False)
Addx = MatchCell.Address

If Not MatchCell Is Nothing Then
Application.ScreenUpdating = False
R = MatchCell.Row
MatchCell.EntireRow.Cut Destination:=DstWks.Cells(LSearchRow, "A")
SrcWks.Rows(R).Delete Shift:=xlShiftUp
Application.ScreenUpdating = True

End If


End Sub
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Forum statistics

Threads
1,224,532
Messages
6,179,388
Members
452,908
Latest member
MTDelphis

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