0
I have a spreadsheet that has two parts and I want to check if both have data.
If the Part 1 and the Part 2 have data, the code paints the corresponding yellow line.
If only one of the parties has data, the code does nothing.
Problem:
If the Part 1 has data and the part 2 it doesn’t have, it works.
If both parts have, it also works by painting yellow.
Now, if only the part 2 has dice, he paints yellow anyway.
This is my code:
Private Sub CommandButton1_Click()
Dim ws As Worksheet
Set ws = Worksheets("Plan1")
Dim i, j, largura, linha As Integer
Dim parte1, parte2 As Boolean
parte1 = False
parte2 = False
largura = 22
linha = 2
For i = 2 To 40
parte1 = False
parte2 = False
For j = 11 To largura 'Conta do 11 até 22 (Referência a posição da coluna)
'verifica as colunas da Parte 1
If ws.Cells(i, j).Value <> "" Then
parte1 = True
End If
If j > 16 Then 'Inicia a verificação das colunas referentes a Parte 2
If ws.Cells(i, j).Value <> "" Then
parte2 = True
End If
End If
'Verifica se ambas as partes possuem dados, se sim, pinta a linha toda de amarelo
If parte1 = True Then
If parte2 = True Then
ws.Cells(i, j).EntireRow.Interior.ColorIndex = 6
End If
End If
Next j
Next i
End Sub
This is the result of that code:
That’s the result I wanted:
Something logical in that code is wrong, but I can’t see.

Your conditions are wrong, check your
Ifs. If you are checking the correct columns. Scroll through your code step by step with the F8 key and you will see what happens in your code...– danieltakeshi