
A seguinte fórmula funciona bemseEu defino cada célula (repetidamente), mas preciso de um loop que percorra as colunas A e B por centenas de linhas. Eu tentei e simplesmente não consigo escrever um loop que seja executado e pare quando atingir uma célula vazia na parte inferior. Isso precisa ser executado em várias planilhas com nomes de guias diferentes.
Exemplo do que funciona agora: [Quero ter uma fórmula que faça um loop] Atualmente tenho isso escrito para 100 linhas, pois não consigo fazer um loop funcionar. :-(
Sub Hidelines()
If Range("A1").Value = "No" Then
Rows("1:1").EntireRow.Hidden = True
ElseIf Range("B1").Value = "NEVER" Then
Rows("1:1").EntireRow.Hidden = True
End If
If Range("A2").Value = "No" Then
Rows("2:2").EntireRow.Hidden = True
ElseIf Range("B2").Value = "NEVER" Then
Rows("2:2").EntireRow.Hidden = True
End If
If Range("A3").Value = "No" Then
Range("E3").Select
Rows("3:3").EntireRow.Hidden = True
ElseIf Range("B3").Value = "NEVER" Then
Rows("3:3").EntireRow.Hidden = True
End If
End Sub
Responder1
Sub HideRows()
Dim RowCount: RowCount = 1 ' Row you wish to start from
Dim ColIndex: ColIndex = 1 ' Column to look within (A = 1) - Never will be in ColIndex + 1
Do
If (LCase(Cells(RowCount, ColIndex).Value) = "no") Then
Cells(RowCount, ColIndex).EntireRow.Hidden = True
ElseIf (LCase(Cells(RowCount, ColIndex + 1).Value) = "never") Then
Cells(RowCount, ColIndex).EntireRow.Hidden = True
End If
RowCount = RowCount + 1
Loop Until IsEmpty(Cells(RowCount, ColIndex).Value)
End Sub
Isso continuará descendo cada linha até atingir uma célula vazia na coluna ColIndex
. Ele examinará sem distinção entre maiúsculas e minúsculas a mesma coluna for No
ou a coluna à direita dela for Never
e ocultará a linha em caso afirmativo.