Error 13 in macro: the types do not match

0

When creating the next macro to copy, from one sheet to another only the cells that meet the condition, the execution shows me this error:

  

"error '13': the types do not match"

Code:

Sub CondicionalTopTxx()

Dim OrigenHoja As Excel.Worksheet, _
    DestinoHoja As Excel.Worksheet, _
    a As Integer

Set OrigenHoja = Worksheets("TNC D")
Set DestinoHoja = Worksheets("TNC B")

OrigenHoja.Activate

    For a = 2 To 40

    Set valor = OrigenHoja.Cells(a, 17)

      If valor.Value < 4 Then

      Range("O14:S16").Copy
      DestinoHoja.Range("O14:S16").PasteSpecial xlPasteAll
      Application.CutCopyMode = False

      End If

    Next

End Sub

How can I select only the range that meets the condition?

    
asked by Calej 10.05.2018 в 11:47
source

1 answer

1

It is not clear what you want to do but it is clear that one of the problems of your Sub procedure is that Worksheets("TNC B").Range("Q14:Q16").Value returns an object of type Variant that is an array and then you compare it with a number ( valor <= 3 )

Maybe you should use a loop to go through all the values in the array.

    
answered by 11.05.2018 в 05:18