jeudi 26 novembre 2020

Excel VB to copy rows from 1 sheet to another based 2 criteria met

I have zero VBA experience. I am trying to use an IF statement to met two criteria in rows on a sheet labeled Master. the criteria are if Column D = "Active" & Column E = "Spanish", I want to copy that row over to a Sheet labeled Spanish, but I do not want Columns D & E to copy over to Spanish sheet.

Here is what I am working on, but I keep getting a Compiling error. What am I doing wrong?

Sub TransferValues()

Dim Emp1a As String, Emp1b As String
With Worksheet("Sheet1")
    If .Range("D2:D30") = "Active" And .Range("E2:E30") = "Spanish"
    Emp1a = .Range("B2:C30")
    Emp1b = .Range("F2:I30")
End With

 Sheet2.Range("B2:C30") = Emp1a
 Sheet2.Range ("D2:G30") - Emp1b
    
 Debug.Print Emp1a
 Debug.Print Emp1b

End Sub

Aucun commentaire:

Enregistrer un commentaire