I'm currently working on a code that finds a certain value then copies all of the rows from the original sheet onto the second sheet that contains that specific value. It works except I can only apply it to one text and I need to add 51 special values that need to be copied. I know that's a lot but I'm working with a lot of data. If I need to copy and paste a certain type of code 51 times to make it works ill do that however I cant figure out how to make it so this code looks up more values.
Also, when the code runs, the sheet its being pasted to has a header but the rows get pasted in the third row down not the second. not sure why it left a blank row right underneath the headers. And is it possible for the rows that get copied are then deleted from sheet 1(where its getting copied from)?
This is the code I'm working with, the portion that goes If CStr(DataRg(I).Value) = "Special Value" Then i tried to duplicate and use different values but it didnt work.
Sub NYC()
Dim DataRg As Range
Dim DataCell As Range
Dim P As Long
Dim J As Long
Dim I As Long
P = Worksheets("DLS-Route").UsedRange.Rows.Count
Q = Worksheets("NYC Source").UsedRange.Rows.Count
If I = 1 Then
If Application.WorksheetFunction.CountA(Worksheets("NYC Source").UsedRange) = 0 Then Q = 0
End If
Set DataRg = Worksheets("DLS-Route").Range("B1:B" & P)
On Error Resume Next
Application.ScreenUpdating = False
For I = 1 To DataRg.Count
If CStr(DataRg(I).Value) = "Special Value" Then
DataRg(I).EntireRow.Copy Destination:=Worksheets("NYC Source").Range("A" & Q + 1)
Q = Q + 1
End If
Next
Application.ScreenUpdating = True
End Sub