Você tem alguns problemas com seu código. Em primeiro lugar, Range("E39, E40, E41")
não se refere a essas três células. Você precisaria separá-los com vírgulas fora das aspas como Range("E39", "E40", "E41")
.
Em segundo lugar, para avaliar corretamente se essas células estão vazias, é necessário separá-las na instrução IF
, desta forma:
If Range("E39") = "" Or Range("E40") = "" Or Range("E41") = "" Then
'code here
End If
O mesmo vale para o IsError:
If IsError(Range("E39")) Or IsError(Range("E40")) ...
No entanto, para agrupar a lógica, você precisa pensar de uma maneira diferente, porque isso gerará o erro quando alguma dessas células estiver vazia / contiver um erro. Então, o que você pode considerar é adicionar duas novas variáveis que você define como True
ou False
dependendo se o grupo está preenchido corretamente ou não. Exemplo:
Dim isFilled1 as Boolean = False
Dim isFilled2 as Boolean = False
If Not Range("E39") = "" Or Not Range("E40") = "" Or Not Range("E41") = "" Then
'All the cells in this range contain a value so set isFilled1 to True
isFilled1 = True
End If
If IsError(Range("E39")) Or IsError(Range("E40")) Or IsError(Range("E40")) Then
'The cells may contain values, but one or more evaluated as an error therefore set isFilled1 to False
isFilled1 = False
End If
If Not Range("A39") = "" Or Not Range("A40") = "" Or Not Range("A41") = "" Then
'All the cells in this range contain a value so set isFilled2 to True
isFilled2 = True
End If
If IsError(Range("A39")) Or IsError(Range("A40")) Or IsError(Range("A40")) Then
'The cells may contain values, but one or more evaluated as an error therefore set isFilled2 to False
isFilled2 = False
End If
'Now check if isFilled1 or isFilled2 are True
If isFilled1 = True or isFilled2 = True Then
'Hooray, one of the groups is properly filled
Else
'Neither group is properly filled; show msgbox
MsgBox("error msgbox")
End If
Você pode precisar ajustar esse código para se adequar à sua situação, mas é assim que eu abordaria isso.