I am working on separating out data according to the value of a cell in a row. In this example I have it so that if any cells in Column Y = "X" then it will paste the entire row into the correct tab.
I am using some code that I found on here that works perfectly to take the data and dump it into the new tab. This is good for generating new data weekly, but I also want a tab that will paste the data on the end of existing data to keep a yearly tally.
This is the code I'm working with.
Sub Paste()
Dim c As Range
Dim j As Integer
Dim Source As Worksheet
Dim Target As Worksheet
Set Source = ActiveWorkbook.Worksheets("Data All")
Set Target = ActiveWorkbook.Worksheets("Data X")
j = 2
For Each c In Source.Range("Y1:Y300")
If c = "X" Then
Source.Rows(c.Row).Copy Target.Rows(j)
j = j + 1
End If
Next c
End Sub
With my limited understanding, it seems that the "j = 2" part means that it begins pasting on the 2nd row.
I tried using this similar code that pastes it to the next available row: Last Row Paste to different Worksheet VBA
I used the "dim lRow As Long" and removed the references to j and just tried to make it
Source.Rows(c.Row).Copy Target.Rows(lRow)
but that doesn't seem to work. Does anybody have an insight? I want to keep it as simple as possible.