VBA: cómo resaltar cuando contiene un texto

VBA: cómo resaltar cuando contiene un texto

Estoy teniendo el siguiente error

Error de tiempo de ejecución '13':

Tipo no coincidente

con el siguiente código. Por favor ayuda.

Sub test()
   ' With Range("A1:C10")
       ' .Value = ""true""
    ' End With
    If Range("h1:h10").Value = "TRUE" Then
       Cells("h, 1").Interior.Color = vbRed    
   End If
End Sub

Respuesta1

Si desea comprobar si todo el rango contiene al menos una celda con texto, puede utilizar:

   if WorksheetFunction.CountA(Range("h1:h10")) = 0  then   
       Cells("h, 1").Interior.Color = vbRed   
   End If

Pero si desea verificar cada celda y colorearla si tiene texto, puede recorrer el rango como:

For i = 1 To 10
    With Cells(i, 1)
        If .Value <> "" Then .Interior.Color = vbRed
    End With
Next i

información relacionada