1

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
Noé Rubinstein
  • 786
  • 6
  • 17
Rick McC
  • 11
  • 1

1 Answers1

1

For your if statement you seem to be are using a block, because you have two things you want to happen on the line after so the syntax is

if <condition> then

    <statements for true>

else (optionally)

    <statements for false> (optionally)

end if

so you need a "then" at then end of your if line, and an "end if", on the line before the end with.

On the " Sheet2.Range ("D2:G30") - Emp1b" did you mean to use minus and not =?

Could you post the error and the line number it happens at?

General Grievance
  • 4,555
  • 31
  • 31
  • 45