0

I have the below code that copies rows from one worksheet to another based on a date range in column B. However, struggling to add a second condition that would eliminate results based on another column (C) containing text "Action". Can anyone help on this?

Private Sub CommandButton3_Click()
    Dim startdate As Date, enddate As Date
    Dim rng As Range, destRow As Long
    Dim shtSrc As Worksheet, shtDest As Worksheet
    Dim c As Range

    Set shtSrc = Sheets("Tier2")
    Set shtDest = Sheets("Parameters")

    destRow = 74 

    startdate = DateSerial(Year(Now), Month(Now), 1)
    enddate = DateSerial(Year(Now), Month(Now) + 3, 0)


    Set rng = Application.Intersect(shtSrc.Range("B:B"), shtSrc.UsedRange)


    For Each c In rng.Cells
        If c.Value >= startdate And c.Value <= enddate Then

            c.Offset(0, 1).Resize(1, 10).Copy _
                          shtDest.Cells(destRow, 1)

            destRow = destRow + 1

        End If
    Next

End Sub

1 Answer 1

1

Use offset to compare the data in column C.
Add the following condition inside your If statement, appended with And

For Each c In rng.Cells
  If c.Value >= startdate And c.Value <= enddate And c.Offset(0, 1) <> "Action" Then
     '....code.... 
  End If
Next c 
Sign up to request clarification or add additional context in comments.

1 Comment

Nothing to be ashamed about, sometimes the easiest of solutions are the ones that takes us the longest to realize ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.