I have two sheets. Sheet 1 (Customer tracker - OC) has a column which contains either yes or no for every row. If the value is yes , the two adjacent cells to the right have two values in them.
I would like to create a do while / for each macro that cycles through each cell in the yes/no column in sheet1, and where the value is yes , creates a new row in the blank sheet 2 which the two adjacent values from sheet 1.
I.e
Sheet1
A B C
1 YES 4 6
2 NO
3 YES 91 42
desired result in sheet 2 ("contracts")
A B
1 4 6
2 91 42
I have the below code , but it's erroring with "overflow".
Sub ForEach_Loop()
Dim TrackerLastRow As Integer
Dim TrackerCurrentRow As Integer
Dim ContractLastRow As Integer
Dim ContractCurrentRow As Integer
TrackerLastRow = Worksheets("Customer Tracker - OC").Range("T1").End(xlDown).Row
TrackerCurrentRow = 1
ContractLastRow = Worksheets("Contracts").Range("A1").End(xlDown).Row
ContractCurrentRow = 1
Do While TrackerCurrentRow <= TrackerLastRow
If Worksheets("Customer Tracker - OC").Range("T" & TrackerCurrentRow).Value = "Yes" Then
Worksheets("Contracts").Range("A" & ContractCurrentRow) = Worksheets("Customer Tracker - OC").Range("T" & TrackerCurrentRow).Offset(, 1).Value
Worksheets("Contracts").Range("B" & ContractCurrentRow) = Worksheets("Customer Tracker - OC").Range("T" & TrackerCurrentRow).Offset(, 2).Value
TrackerLastRow = TrackerLastRow + 1
TrackerCurrentRow = TrackerCurrentRow + 1
ContractLastRow = ContractLastRow + 1
ContractCurrentRow = ContractCurrentRow + 1
End If
TrackerCurrentRow = TrackerCurrentRow + 1
ContractCurrentRow = ContractCurrentRow + 1
Loop
End Sub
Any help would be appreciated