0

I have a question regarding this post (VBA copy rows that meet criteria to another sheet)

His script:

Sub LastRowInOneColumn()
'Find the last used row in a Column: column A in this example
    Worksheets("Sheet2").Activate
    Dim LastRow As Long
    With ActiveSheet
        LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
    End With
    MsgBox (LastRow)
    For i = 1 To LastRow
    If Worksheets("Sheet2").Cells(i, 1).Value = "X" Then
    ActiveSheet.Row.Value.Copy _
    Destination:=Hoja1
    End If
    Next i
 End Sub

I wonder if there are multiple conditions in just 1 If statement. The idea is to copy and paste data to another sheet if column1 = "X", or column2 ="Y", or (column1 = "X" and column2 = "Y"). I changed by myself and run, but the output sheet looks quite weird.

If Worksheets("Sheet2").Cells(i, 1).Value = "X" Or _
   Worksheets("Sheet2").Cells(i, 2).Value = "Y" Or _
   (Worksheets("Sheet2").Cells(i, 1).Value = "X" And _
    Worksheets("Sheet2").Cells(i, 2).Value = "Y") Then
Tim Williams
  • 154,628
  • 8
  • 97
  • 125
Laura
  • 35
  • 5

0 Answers0