Using VBA, how do I:
Copy cell B1 in Worksheet1 to a new Worksheet2 only if cell A1 (in Worksheet1) value = "YES".
This then repeats for each row in range A1:A1000 (i.e. B2 copies based on A2 value = "YES" and so on) - if cell is blank, check next row.
Sub Output()
Dim c As Range
Dim j As Integer
Dim Source As Worksheet
Dim Target As Worksheet
Set Source = ActiveWorkbook.Worksheets("worksheet1")
Set Target = ActiveWorkbook.Worksheets("worksheet2")
j = 1 ' Start copying to row 1 in target sheet
For Each c In Source.Range("R2:R1000") ' Do 1000 rows
If c = "YES" Then
Source.Rows(c.Row).Copy Target.Rows(j) /*getting stuck here on trying to copy a cell from column S in worksheet1 to worksheet2
j = j + 1
End If
Next c
End Sub
A1
,A2
, etc, but in your code you are looking in columnR
– PartyHatPanda